Skip to main content
November 6, 2009
Answered

if current frame == 1 dosomething ... else (currentFrame ==2) do something else. Not working.

  • November 6, 2009
  • 2 replies
  • 11339 views

Im having a little bit of trouble trying to make a button give me different results based on what frame the main timeline is on.

I am trying to get a button to go to a different link based on what frame the main timeline is on.  If I am on frame 5 It will trace back "4" .. that is fine but other frames trace back the frame number and also 4.

frame 2 click of button traces back 1 and 4

frame 3 click of button traces back 2 and 4

frame 4 click of button  traces back 3 and 4

frame 5 click of button  traces back 4

thanks for your advice.

function buttonClicked(e:Event):void
{
     if(currentFrame == 2)
     {
          trace("Clicked 1");
     }
     else if(currentFrame == 3)
     {
          trace("Clicked 2");
     }
     else if(currentFrame == 4)
     {
          trace("Clicked 3");
     }
     else (currentFrame == 5)
     {
          trace("Clicked 4");
     }
}

This topic has been closed for replies.
Correct answer Kalisto

You have a misstake    else   (currentFrame == 5) do nothing but it is used for else. After that  trace("Clicked 4"); is simple command

or in other words:

else  (currentFrame == 5)
{
          trace("Clicked 4");

}

is equal to

else  (currentFrame == 5)

trace("Clicked 4"); // this will alway be executeds

2 replies

KalistoCorrect answer
Inspiring
November 6, 2009

You have a misstake    else   (currentFrame == 5) do nothing but it is used for else. After that  trace("Clicked 4"); is simple command

or in other words:

else  (currentFrame == 5)
{
          trace("Clicked 4");

}

is equal to

else  (currentFrame == 5)

trace("Clicked 4"); // this will alway be executeds

clbeech
Inspiring
November 6, 2009

LMAO!  omg, kalisto - i can't believe i didn't see that! PHAHAHAHAHAH!

Inspiring
November 6, 2009

And "LMAO" is?

clbeech
Inspiring
November 6, 2009

hmmm - well it seems that the final 'else' is causing the statement to fail - not certain why at this time - odd in a way - however to remedy, use an 'if else' as the final condition.  also you'll want to change the event object type to MouseEvent - rather than just Event