|
-
Senior Member
This one'll blow your mind. You can do the same thing in one line.
code:
isPaused = false;
this.movieClip.play_btn.onRelease =
function()
{
gotoAndStop(5 - (isPaused ^= 1)*4);
}
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 ? :
code:
isPaused = !isPaused;
gotoAndStop(isPaused? 1 : 5);
Last edited by jbum; 10-22-2004 at 12:51 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|