I want to have one button that has two states. For example a play button, when pressed it plays a movie, but change to a pause button. Then you can click the pause button and it returns to the original state.
So far, i have created a moiveclip, inside i have my button. On frame 1 i have the play button and on frame 5 i have my pause button. I want to have a action on release, so that the button change from one frame to the next. Does this make sense?
I don't recommend this method, however, since it makes the code hard to understand.
Here's what is going on - I'll build it up bit by bit.
isPaused ^= 1;
This toggles the 1 bit in isPaused by using the XOR operator. The result is the new value of isPaused, which will be 0 or 1. So we get 0,1,0,1,0,1 etc.
(isPaused ^= 1)*4
We multiply that by 4, which gives us 0,4,0,4,0,4, etc.
5 - (isPaused ^= 1)*4
5-0 = 5
5-4 = 1
so this toggles back and forth between frame 5 and frame 1.
Now, here's a 2-line version which I would use. It uses the conditional operator ? :
Most of the scripts I post here are Flash 6 (Flash MX), and work with actionscript 1.0. Many of them also work in Flash 5, and this particular one probably does.
the result was an undefiined object. you would have to write a new constructor function in order for this.movieClip.gotoAndStop(isPaused? 1 : 5) line of code to be applicable.
I have another questions about calling actions to the button. In the two different states i want to have different actions called upon the button, but the button has the same instance name. How do i get around this?