Link to home
Start Free TrialLog in
Avatar of simplicitytheory
simplicitytheory

asked on

how do I get my if statement to execute once, when its condition is met?

Hey all,

Im trying to create a little menu here. It has 8 options (with rollon animation, selected, rolloff animation), so I thought I would have a variable for each menu option.

So when menu option 1 is selected my variable (navvar) will = 1.

Here is my if statement / loop.

//for option1
if(_root.navvar == "1"){
_root.nav_main.home.gotoAndPlay("onanimation");
}

//options 2-8 like above else if(_root.navvar == "2"){ etc

Now my problem is that when the above is looping over its 2 frames, obvisouly it only plays a few frames of my "onanimation", which means I get a flickering effect.

Could someone show me how I can setup this code so that when navvar = 1 I can simply go and play my "onanimation" once only, (until another variable is selected etc)

Any help is much appreciated.
Avatar of Proactivation
Proactivation
Flag of United Kingdom of Great Britain and Northern Ireland image

Just add a frame action of stop(); on the last frame of your animation, then it won't loop.
Avatar of simplicitytheory
simplicitytheory

ASKER

Ive got one already there.
Hmm.. in which case, what does this do?:

_root.nav_main.home.gotoAndStop("onanimation");
so _root.nav_main.home only has 2 frames, and the second frame contains the animation?

if so, why not try gotoAndStop()?

//for option1
if(_root.navvar == "1"){
_root.nav_main.home.gotoAndStop("onanimation");
}
another solution i like is to make my buttons control movie clip animations by setting an 'onEnterFrame' action that makes them move forward or backward thru the animation.. this would work well for you because it doesn't tell them to 'play', it just tells them to advance forward or backward:

on (rollOver) {
      _root.nav_main.home.onEnterFrame = function() {
            _root.nav_main.home.nextFrame();
      };
}
on (rollOut) {
      _root.nav_main.home.onEnterFrame = function() {
            _root.nav_main.home.prevFrame();
      };
}
i'm not sure i understand ur file setup...

>>above is looping over its 2 frames

you have the root with 2 frames? or _root.nav_main or _root.nav_main.home?
rythmik1 I have posted my code here. If you get a chance take a look and let me know what you think would be the best solution. Ill have a look into onEnterFrame, havent used it much before.

http://users.ncable.net.au/~timfrancis/menutestingmx.swf
http://users.ncable.net.au/~timfrancis/menutestingmx.fla
SOLUTION
Avatar of blue-genie
blue-genie
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Unfortunatley this is just not simple on, off, paused menu.

I am setting it up so that when I am on a page, that menu option will be turned on. So you will not be able to have roll on or roll of animations on that particular option when it is on that particlar page.

I have cleaned it up a little and reposted.

http://users.ncable.net.au/~timfrancis/menutestingmx_v1.fla

At present, I am trying to get my option1 menu to turn off when the variable is not equal to 1.

I thought to do this I would add a not equal to 1 statement in my main if statement such as:

if(navvar == 1){
this.option1.gotoAndStop("paused");//if navvar is equal to 1 the button will look like its on (full red)
}
else if (navvar != 1){
this.option1.gotoAndStop(1);// if navvar is not equal to 1 it will be in an off state, ready to be rolled over
}

But Im stuck right at this point, as when I change the variable to 2 or 3, option1 stays at its paused position.
Hi again guys Ive now got it pretty well done only one issue remains.

I have a delay issue, where when I rollover an option (that is currently not set to its corresponding variable/turned on) I am telling it to go to the on animation. This works but if you quickly roll on and off and dont give the onanimation enough time to get to 20 (finish) before you roll off when obviously it gets stuck on at 20 because I have a stop();.

//eg for option1
this.onRollOver = function(){
if (_root.navvar == 1 &&_currentframe == 20){//if navvar = 1, this item is already selected so we dont need the on animation to play
this.stop(); //so tell this mc to stay at its paused/on state/ (at 20)
}
else{ //if its not at its paused state it means the option is unselected and we will allow it to play its on animation
gotoAndPlay("on");//this plays till frame 20
}
}

Could someone show me a way around this.

Reposted my file http://users.ncable.net.au/~timfrancis/menutestingmx_v2.fla