|
|
|
#1 |
|
Flash or die
Join Date: May 2004
Location: San Francisco, California
Posts: 127
|
2-State Button - Need Help
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? Here is my code to call this action: Code:
this.movieClip.play_btn.onRelease = function() {
gotoAndStop(5)
};
__________________
// rocking flash cs4,as3 |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Aug 2000
Location: Vermont
Posts: 269
|
i imagine that your code of:
this.movieClip.play_btn.onRelease = function() { gotoAndStop(5) }; is nested inside some other object creating function - if so you may want to post the entire function. if not try this: movieClip.play_btn.onRelease = function() { movieClip.gotoAndStop(5); }; i have a feeling it is a targeting issue.. post your fla if want |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
|
This adds a toggle behavior to the button.
The variable isPaused flips back and forth between true and false when this line executes: isPaused = ! isPaused; Then you use that variable to change the behavior or look of the button.
|
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Aug 2000
Location: Vermont
Posts: 269
|
hey jbum, very interesting, never seen this usage of toggling -> isPaused = ! isPaused; -> learn something new everyday
sorry exuk, i think i need to read people's posts more thoroughly.. long day for me. |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
|
This one'll blow your mind. You can do the same thing in one line.
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 ? :
Last edited by jbum; 10-22-2004 at 01:51 AM. |
|
|
|
|
|
#6 |
|
Super Moderator
Join Date: Aug 2000
Location: Montréal
Posts: 13,430
|
It blew mine. You're an artist, jbum!
gparis
__________________
![]() AS 2.0 Forum Guidelines || Use P H P tags for code samples || Flash LiveDocs || AS 2.0 Language reference (CS4) |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Aug 2000
Location: Vermont
Posts: 269
|
i feel like a newb again.
haven't had time to play around with your AS yet.. but out of curiosity what minimum version of flash does the movie need to be published as?
thanks. |
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
|
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.
I don't do much coding in actionscript 2.0 yet. |
|
|
|
|
|
#9 |
|
Flash or die
Join Date: May 2004
Location: San Francisco, California
Posts: 127
|
Thanks for all the help from both of you. I tried the code without yeilding results. I am going to post the fla file. Can someone help me with this?
__________________
// rocking flash cs4,as3 |
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Aug 2000
Location: Vermont
Posts: 269
|
this works
this seemed to do the trick, added some trace actions so you can see what is going on:
Code:
isPaused = true;
this.movieClip.play_btn.onRelease = function() {
isPaused = !isPaused;
trace ("Value of isPaused: " + isPaused);
_root.movieClip.gotoAndStop(isPaused? 1 : 5);
trace ("MovieClips Current Frame: " + _root.movieClip._currentFrame);
}
Code:
_root.movieClip.gotoAndStop(isPaused? 1 : 5); Code:
this.movieClip.gotoAndStop(isPaused? 1 : 5); |
|
|
|
|
|
#11 |
|
Flash or die
Join Date: May 2004
Location: San Francisco, California
Posts: 127
|
OK Thanks!. Sometimes i mess up on the paths, but the _root was the fix.
For all reading this thread i am going to post the working fla.
__________________
// rocking flash cs4,as3 |
|
|
|
|
|
#12 |
|
Flash or die
Join Date: May 2004
Location: San Francisco, California
Posts: 127
|
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?
__________________
// rocking flash cs4,as3 |
|
|
|
|
|
#13 |
|
Junior Member
Join Date: Dec 2000
Posts: 4
|
maybe i'm not getting something really simple here but, i added an mc to the main timeline of that file and it doesnt pause it
|
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|