Skip to main content
Participant
April 16, 2009
Question

AS3 If statement

  • April 16, 2009
  • 3 replies
  • 1252 views

Hi

I have managed to get my timeline to play and pause at various points but I have created a review page, on this there are buttons which link to the start of the different sections. What I want to happen is if the scene has already been viewed, after it has been viewed, the user should be redirected to the review page.

This is my code which stops but does not redirect the user if they have already viewed the section.

stop();

var a:Number = 1;

play396_btn.addEventListener(MouseEvent.MOUSE_UP, goplay396, false, 0, true);

function goplay396(evt:MouseEvent):void{

if (a == 2) {

gotoAndPlay(1755);

}

else {

a=2;

play()

}

}

Could someone help me
Thanks
Himesh

This topic has been closed for replies.

3 replies

himesh_sAuthor
Participant
April 17, 2009

Hi

thanks for all your input, I have set the variable a in frame one of the entire sequence, taken it out of the code which have posted and this has solved the problem.

Thanks again

Himesh

kglad
Community Expert
Community Expert
April 17, 2009

you're welcome.

xchanin
Participating Frequently
April 16, 2009

You should name your frames instead of using the frame number,thsi way if you happen to add or subtract frames from the timeline you don't have to go back and make adjustments in your code. What is probably happening, is that the 'a' variable is changing back to a value of 1.

Are you adding the if statement on the frame you're checking?

himesh_sAuthor
Participant
April 16, 2009

Hi

I was thinking that the variable was changing back to 1 but im new to this so I wasnt sure and yes I have added the code to the frame im checking. If i get the code right here I was going to add the code to the other frames I want this to happen on.

Himesh

xchanin
Participating Frequently
April 16, 2009

I'm pretty sure that is what's happening, the value of 'a' is being reset to one. If you are setting the variable on frame one and you can avoid going back to frame one, then the value of 'a' shouldn't change back to one.

kglad
Community Expert
Community Expert
April 16, 2009

what are you using to indicate if "the" scene has been viewed and what's the review page's frame number or label?

himesh_sAuthor
Participant
April 16, 2009

I was using the variable a.

I thought if i defined it and then updated it once it has been viewed, the if statement will recognise this and redirect the user to the review page which is frame number 1756.

Thanks

Himesh

Ned Murphy
Legend
April 16, 2009

You say the user stops for this code, so is "a" being reset to 1 all the time?  You should trace the value of "a" in the function to see what it is under the different circumstances.