08-15-2012, 08:39 AM
|
#1
|
|
Registered User
Join Date: Aug 2012
Posts: 4
|
Button that affects movie clip?
I guess this question might be pretty basic, but I can't seem to find an answer anywhere.
Mainly, I have a movie clip with 6 frames, I also have a button outside the movie clip which I want to use to change the frame the movie clip is on.
Is this possible? And which code should I put on the button?
|
|
|
08-15-2012, 04:35 PM
|
#2
|
|
Prid - Outing
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,157
|
ActionScript Code:
on(press){
my_movieclip.play();
}
and then on each Frame in your Movieclip, use, stop();
also, give your Movieclip and instance name of, for example, my_movieclip (if you change it, change it in the code as well). Do this by selecting the Movieclip, opening Properties Panel [CTRL+F3], and typing it in the Instance Name textfield.
that's the easiest way, because I'm assuming you're new to Actionscript, right?
__________________
17 Years old boy, who loves the Computer Technology
|
|
|
08-15-2012, 06:18 PM
|
#3
|
|
Registered User
Join Date: Aug 2012
Posts: 4
|
Thanks for answering  (Btw. I am from Norway too)
But it didn't really work :/
This is the code I put in my button:
on(press){ my_movieclip.play("Frame 2"); }
However nothing happened when I pressed the button...
|
|
|
08-15-2012, 08:19 PM
|
#4
|
|
ˇCapitán Voz de la Rádio!
Join Date: Dec 2011
Location: Cincinnati, OH, USA
Posts: 14
|
You don't need any parameters inside the parentheses. Remove "Frame 2".
If you have stop(); on each frame of the movie clip, it will advance one frame each time you click the button.
|
|
|
08-16-2012, 07:45 AM
|
#5
|
|
Registered User
Join Date: Aug 2012
Posts: 4
|
Ok, but I kind of need one button to go to each frame so there are actually 6 buttons, sorry I forgot to mention that.
|
|
|
08-16-2012, 04:01 PM
|
#6
|
|
ˇCapitán Voz de la Rádio!
Join Date: Dec 2011
Location: Cincinnati, OH, USA
Posts: 14
|
In that case, each button should have this:
Code:
on(press){
my_movieclip.gotoAndPlay(#);
}
Where you replace # with the number of the frame to which you want that particular button to advance.
One thing you may run into is a case where, if you press the button that goes to frame 2, but the movie clip is already on frame 2, it may go to frame 3 (because Flash is weird like that). I'd add an if-statement to check and make sure the movie clip isn't already on that frame:
Code:
on(press){
if (my_movieclip._currentframe != #) {
my_movieclip.gotoAndPlay(#);
}
}
With this, the button will only act if the movie clip isn't already on the frame that button wants to go to. If it's already on that frame, why tell it to go to the same place?
|
|
|
08-16-2012, 11:19 PM
|
#7
|
|
Prid - Outing
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,157
|
Hi,
cool that you're from Norway too
props to CaptRadioVoice for the great solution
as for the problem where it can go to the next frame when telling it to goto and play to that frame when it's already on that frame (lolz, kinda confusing but you get the idea:P), it happens because gotoAndPlay goes to the specified Frame and then continues playing from there, but wait, isn't there a stop() function on that Frame, you may ask? Yes, but that stop() function is only executed when you get to that Frame, and it only functions ONCE, and then, if you use gotoAndPlay, the stop() function isn't re-executed, because Flash doesn't work like that, if you want it to stop there, you'll have to manually tell Flash to stop there again, hope that clarifies the "weird" situation ^^
A solution for that is to use gotoAnd Stop instead of gotoAnd Play, which goes to a Frame and stops there instead of continue playing
btw, love the way you highlighted # to make it look clean and easy to understand
__________________
17 Years old boy, who loves the Computer Technology
|
|
|
08-17-2012, 11:38 AM
|
#8
|
|
Registered User
Join Date: Aug 2012
Posts: 4
|
Oh, Thank you soo much! It finally worked 
You've both been a big help!
|
|
|
08-17-2012, 05:21 PM
|
#9
|
|
ˇCapitán Voz de la Rádio!
Join Date: Dec 2011
Location: Cincinnati, OH, USA
Posts: 14
|
Quote:
Originally Posted by Prid
A solution for that is to use gotoAnd Stop instead of gotoAnd Play, which goes to a Frame and stops there instead of continue playing 
|
That's a good point as well. I can't remember why, but gotoAndStop(); gave me problems in the past. Now I'm so biased to gotoAndPlay(); I can't go back!
|
|
|
08-18-2012, 06:20 PM
|
#10
|
|
Prid - Outing
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,157
|
Hehe
We all have those stuff we're afraid to code in fear of it messing up. Mine is the short version of if statement. A normal if statement looks like this:
Code:
if(condition){
//some code here
}
while the short version is this:
Code:
if(condition) //some code here
I don't use the short version as I've also encountered problems with it (which later proved to be caused by something else, but still), so I don't want to use it
__________________
17 Years old boy, who loves the Computer Technology
Last edited by Prid; 08-18-2012 at 06:22 PM.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 08:19 PM.
///
|
|