Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-13-2010, 06:36 PM   #1
Slackulator
Senior Member
 
Join Date: Dec 2008
Posts: 124
Exclamation Question about if/else statement on buttons.

Hello,

In my project I have a button which when clicked it makes a movieclip(which includes expanding buttons that appear) to play.
Now, what I want to achieve is to reverse this movieclip animation(make the buttons disappear on reverse animation) IF the button is clicked again.

So, when you click the main button, 5 buttons animate in. I want them to reverse animate(play their timeline backwards?) IF the main button is clicked again.
Imagine it as an open/close menu.

Do I achieve this effect with if else statement?
Thanks in advance
Slackulator is offline   Reply With Quote
Old 07-13-2010, 06:47 PM   #2
snickelfritz
Senior Member
 
Join Date: Jun 2008
Posts: 1,206
Default

Toggle a Boolean variable; if it's false, play forward, then set the variable to true; else, play backward, then set the variable to false;
The default would be false. (buttons not showing)
snickelfritz is offline   Reply With Quote
Old 07-13-2010, 06:47 PM   #3
toli
Senior Member
 
Join Date: Jun 2006
Location: New York
Posts: 374
Default

you can create a var thats a boolean and flip it depending on current action

ActionScript Code:
var goingForward:Boolean = truel function onButtonClick(e:MouseEvent):void { if(goingForward) { //code to go forward goinForward = false; } else { //code to go backwards goinForward = true; } }
toli is offline   Reply With Quote
Old 07-13-2010, 07:31 PM   #4
Slackulator
Senior Member
 
Join Date: Dec 2008
Posts: 124
Default

So, I need to create an over and out state for these 5 buttons, and add gotoAndPlay("over") on if statement and gotoAndPlay("out") on else statement on the code toli suggested?
Can't the animation be reverted(only have one state, over)

Last edited by Slackulator; 07-13-2010 at 07:33 PM.
Slackulator is offline   Reply With Quote
Old 07-13-2010, 07:57 PM   #5
92Garfield
Senior Member
 
Join Date: Jul 2010
Posts: 356
Default

ActionScript Code:
goinForward = !goinForward;

when it's true, it's set to false and vice versa.
92Garfield is offline   Reply With Quote
Old 07-13-2010, 08:16 PM   #6
snickelfritz
Senior Member
 
Join Date: Jun 2008
Posts: 1,206
Default

You only need one animation that runs forwards and backwards.
Forward shows the buttons; backwards hides the buttons.
Use TweenMax to control the playhead.
ActionScript Code:
import com.greensock.*; buttons.gotoAndStop(1); var buttonsVisible:Boolean = false; btn.addEventListener(MouseEvent.CLICK, onClick); function onClick(e:MouseEvent):void {     var targetFrame:Number;     var duration:Number = buttons.totalFrames / stage.frameRate;         if(buttonsVisible)     {         targetFrame = 1;         buttonsVisible = false;     }     else     {         targetFrame = buttons.totalFrames;         buttonsVisible = true;     }     TweenMax.to(buttons, duration, {frame:targetFrame}); }
snickelfritz is offline   Reply With Quote
Old 07-13-2010, 08:35 PM   #7
Slackulator
Senior Member
 
Join Date: Dec 2008
Posts: 124
Default

Thanks a lot for the replies. It worked
Slackulator 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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:43 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.