Skip to main content
Participant
August 28, 2013
Answered

letting a cycle play to a given point before changing scenes

  • August 28, 2013
  • 1 reply
  • 588 views

HI,
I'm new to this forum. I have a question. I have a two scenes. Scene 1 is a cycle 100 frames long. I have a button in the scene, and when I press it, I go to the next scene. I have been able to get this to work.
The problem is when I press the button it goes immediately to the next scene regardless of where it is in the animation, so it looks like a glitch. (Frame 50 of scene 1 is identical to frame 1 of scene 2)
How do I fix it, so that if I press the button that the animation will continue to play until it reaches frame 50 and then go to scene 2?

Thanks a lot for any help

Conor

This topic has been closed for replies.
Correct answer Ned Murphy

Create a Boolean variable in frame 1 that you use in a conditional in frame 50 and have that conditional process the command to go to the next scene.  When you click the button have it change the value of that variable.

//frame 1

var gotoNextScene:Boolean = false;

yourBtn.addEventListener(MouseEvent.CLICK, changeSceneVariable)

function changeSceneVariable(evt:MouseEvent):void {

        gotoNextScene = true;

}

// frame 50

if(gotoNextScene){

      gotoAndPlay(1, "scene2");

}

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
August 28, 2013

Create a Boolean variable in frame 1 that you use in a conditional in frame 50 and have that conditional process the command to go to the next scene.  When you click the button have it change the value of that variable.

//frame 1

var gotoNextScene:Boolean = false;

yourBtn.addEventListener(MouseEvent.CLICK, changeSceneVariable)

function changeSceneVariable(evt:MouseEvent):void {

        gotoNextScene = true;

}

// frame 50

if(gotoNextScene){

      gotoAndPlay(1, "scene2");

}

Participant
August 28, 2013

Hi Ned,

Thanks very much for this, it worked perfectly.

all the best

Conor

Ned Murphy
Legend
August 28, 2013

You're welcome Conor