• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

** Simple IF Statement** URGENT **

Ok,

This should be some easy points.  All I need is a simple IF STATEMENT.  

I have 3 links in my navigation all aligned on the left.  When the user clicks a link, that link will slide to the right. ...then the page will load... And then when/if the user clicks another link, the link clicked before will slide back as the recently clicked link will slide right.  I hope this makes sense.

Thanks

Mtb007
0
mtb007
Asked:
mtb007
  • 8
  • 3
1 Solution
 
rascalpantsCommented:
you can always do this the easy way...

btnFunction=function(btn){
 
 if(btn == 1){
    _root.button1._x = 50;
    _root.button2._x = 5;
    _root.button3._x = 5;
  } else if(btn == 2){
    _root.button1._x = 5;
    _root.button2._x = 50;
    _root.button3._x = 5;
  } else if(btn == 3){
    _root.button1._x = 5;
    _root.button2._x = 5;
    _root.button3._x = 50;
  }

};


button1.onRelease=function(){
  btnFunction(1);
};
button2.onRelease=function(){
  btnFunction(2);
};
button3.onRelease=function(){
  btnFunction(3);
};


just put all of the above code on the first frame of your movie, and give your 3 buttons instance names "button1", "button2", "button3"


there are hundreds of ways to do this, but this seems to work fine...

rp
0
 
mtb007Author Commented:
Thats perfect except for I need it to actually slide right and left. not just jump.
0
 
rascalpantsCommented:
this code might need a little tweaking, but it will get you on your way:

lastBtn = "";

btnFunction=function(btn){
  onEnterFrame=function(){
    if(_root["button" + btn]._x < 50){
      _root["button" + btn]._x = _root["button" + btn]._x + 5;
      _root["button" +_root.lastBtn]._x = _root["button" +_root.lastBtn]._x - 5;
    } else {
      _root.lastBtn = btn;
      endLoop();
    }
  }
}

endLoop=function(){
  onEnterFrame = null;
};

button1.onRelease=function(){
  btnFunction(1);
};
button2.onRelease=function(){
  btnFunction(2);
};
button3.onRelease=function(){
  btnFunction(3);
};



rp
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!

 
mtb007Author Commented:
Ok, one last Q.  Is there are way that you can ease it in and out?  Specifically at the end, so it slows down?
0
 
mtb007Author Commented:
Also, if you click them fast it goes all over the place.
0
 
rascalpantsCommented:
the ease in and out is trig, and I think as a beginner, you should try not to use anything like that...  even I have trouble with that stuff sometimes...  not the best at complex math...


yah, some tinkering needs to be done to the code to keep it all aligned when you click during the loop...

have to brain storm that one...

rp
0
 
rascalpantsCommented:
this will prevent the user from breaking the interface...

lastBtn = 0;
disable = "no";

btnFunction=function(btn){
      _root.disable = "yes";
      onEnterFrame=function(){
            if(_root["button" + btn]._x < 50){
                  _root["button" + btn]._x = _root["button" + btn]._x + 5;
                  _root["button" +_root.lastBtn]._x = _root["button" +_root.lastBtn]._x - 5;
            } else {
                  _root.lastBtn = btn;
                  endLoop();
            }
      }
}

endLoop=function(){
      onEnterFrame = null;
      _root.disable = "no";
};


button1.onRelease=function(){
      if(_root.disable == "no"){
            btnFunction(1);
      }
};
button2.onRelease=function(){
      if(_root.disable == "no"){
            btnFunction(2);
      }
};
button3.onRelease=function(){
      if(_root.disable == "no"){
            btnFunction(3);
      }
};


rp
0
 
rascalpantsCommented:
here is my example:

http://www.kcnewmedia.com  <-- delete these spaces -->  /dev/sliding_menus/

I changed the x position to 100 and change the increment to 25 in both parts of the code, and it runs faster...

rp
0
 
rascalpantsCommented:
I am not sure what you are doing with these things, but you can turn the buttons into movieclips, and create all sorts of navigation functionality and customization.


rp
0
 
rascalpantsCommented:
Jason,

what is the status of this question...

rp
0
 
rascalpantsCommented:
I guess you liked what I did above...

glad to help...


rp
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 8
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now