Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-15-2012, 08:39 AM   #1
KawaiiSairen
Registered User
 
Join Date: Aug 2012
Posts: 4
Default 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?
KawaiiSairen is offline   Reply With Quote
Old 08-15-2012, 04:35 PM   #2
Prid
Prid - Outing
 
Prid's Avatar
 
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,191
Send a message via MSN to Prid Send a message via Skype™ to Prid
Default

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?
__________________
I have returned, and am now 18
Prid is offline   Reply With Quote
Old 08-15-2012, 06:18 PM   #3
KawaiiSairen
Registered User
 
Join Date: Aug 2012
Posts: 4
Default

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...
KawaiiSairen is offline   Reply With Quote
Old 08-15-2012, 08:19 PM   #4
CaptRadioVoice
¡Capitán Voz de la Rádio!
 
Join Date: Dec 2011
Location: Cincinnati, OH, USA
Posts: 14
Default

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.
CaptRadioVoice is offline   Reply With Quote
Old 08-16-2012, 07:45 AM   #5
KawaiiSairen
Registered User
 
Join Date: Aug 2012
Posts: 4
Default

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.
KawaiiSairen is offline   Reply With Quote
Old 08-16-2012, 04:01 PM   #6
CaptRadioVoice
¡Capitán Voz de la Rádio!
 
Join Date: Dec 2011
Location: Cincinnati, OH, USA
Posts: 14
Default

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?
CaptRadioVoice is offline   Reply With Quote
Old 08-16-2012, 11:19 PM   #7
Prid
Prid - Outing
 
Prid's Avatar
 
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,191
Send a message via MSN to Prid Send a message via Skype™ to Prid
Default

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 gotoAndStop instead of gotoAndPlay, 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
__________________
I have returned, and am now 18
Prid is offline   Reply With Quote
Old 08-17-2012, 11:38 AM   #8
KawaiiSairen
Registered User
 
Join Date: Aug 2012
Posts: 4
Default

Oh, Thank you soo much! It finally worked
You've both been a big help!
KawaiiSairen is offline   Reply With Quote
Old 08-17-2012, 05:21 PM   #9
CaptRadioVoice
¡Capitán Voz de la Rádio!
 
Join Date: Dec 2011
Location: Cincinnati, OH, USA
Posts: 14
Default

Quote:
Originally Posted by Prid View Post
A solution for that is to use gotoAndStop instead of gotoAndPlay, 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!
CaptRadioVoice is offline   Reply With Quote
Old 08-18-2012, 06:20 PM   #10
Prid
Prid - Outing
 
Prid's Avatar
 
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,191
Send a message via MSN to Prid Send a message via Skype™ to Prid
Default

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
__________________
I have returned, and am now 18

Last edited by Prid; 08-18-2012 at 06:22 PM.
Prid is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:00 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.