Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

** Simple IF Statement** URGENT **

Posted on 2004-04-22
11
210 Views
Last Modified: 2010-04-03
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
Comment
Question by:mtb007
  • 8
  • 3
11 Comments
 
LVL 22

Expert Comment

by:rascalpants
ID: 10892626
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
 
LVL 1

Author Comment

by:mtb007
ID: 10892750
Thats perfect except for I need it to actually slide right and left. not just jump.
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 10893359
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 1

Author Comment

by:mtb007
ID: 10893418
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
 
LVL 1

Author Comment

by:mtb007
ID: 10893441
Also, if you click them fast it goes all over the place.
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 10893630
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
 
LVL 22

Accepted Solution

by:
rascalpants earned 250 total points
ID: 10893895
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
 
LVL 22

Expert Comment

by:rascalpants
ID: 10893974
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
 
LVL 22

Expert Comment

by:rascalpants
ID: 10893991
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
 
LVL 22

Expert Comment

by:rascalpants
ID: 10918436
Jason,

what is the status of this question...

rp
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 10918488
I guess you liked what I did above...

glad to help...


rp
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
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 goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

840 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