?
Solved

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

Posted on 2006-05-10
11
Medium Priority
?
166 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:simplicitytheory
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 12

Expert Comment

by:Proactivation
ID: 16656364
Just add a frame action of stop(); on the last frame of your animation, then it won't loop.
0
 

Author Comment

by:simplicitytheory
ID: 16657049
Ive got one already there.
0
 
LVL 12

Expert Comment

by:Proactivation
ID: 16657579
Hmm.. in which case, what does this do?:

_root.nav_main.home.gotoAndStop("onanimation");
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:rythmik1
ID: 16657665
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");
}
0
 
LVL 2

Expert Comment

by:rythmik1
ID: 16657693
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();
      };
}
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 16658627
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?
0
 

Author Comment

by:simplicitytheory
ID: 16658656
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
0
 
LVL 39

Assisted Solution

by:blue-genie
blue-genie earned 100 total points
ID: 16658790
i had a look at your file - what flickering are you referring to?
it seems to me the file is doing exactly what you're telling it to do, in terms of it goes to the frame 50 and waits there till you click something else.

0
 
LVL 2

Accepted Solution

by:
rythmik1 earned 100 total points
ID: 16658814
i think your basic issue here is that your movie is set up way more complicated than necessary. i'm not even sure what exactly you're trying to accomplish with all the  nested movie clips and buttons the way they're set up. my advice is to start over and think more simply. put a movie clip on the root timeline that contains an animation and a stop() on the first frame. then put a button on the timeline and make it control that movie with the code i wrote above. that will give you a basis for controling animations with rollovers that you can branch out from without all the complexity.

here's a sample to get you started: http://paulsandersdesign.com/flash/button_controls_movie.fla

0
 

Author Comment

by:simplicitytheory
ID: 16664135
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.
0
 

Author Comment

by:simplicitytheory
ID: 16664770
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
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
Suggested Courses
Course of the Month15 days, 22 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question