Copy link to clipboard
Copied
I've been looking everywhere on how to do this, and can't find anything!
So, I have this code right here -
button1.addEventListener(MouseEvent.CLICK, goScene2);
function goScene2(event:MouseEvent):void {
gotoAndPlay(1,"Scene 2");
}
So, lets say scene 1 has 40 frames. Someone clicks on the button to go to the next scene at frame 10. I want it to continue to frame 40, then change to the next scene.
Keep in mind that the 40 frame scene is on loop, so it could loop 4 or 5 times, then someone clicks next scene. So, I want it to finish the loop, then go to the next scene.
Copy link to clipboard
Copied
set a variable at the beginning of your movie:
var clicked:Boolean = false;
then in your MouseEvent set it to true
function goScene2(event:MouseEvent):void {
clicked = true;
}
then in the 40th frame of your first scene:
if(clicked){
gotoAndPlay(1,"Scene 2");
}
else{
// continue the loop
gotoAndPlay(1,"Scene1);
}
Copy link to clipboard
Copied
I'm getting an argument error -
Error #2108: Scene Scene1 was not found.
at flash.display::MovieClip/gotoAndPlay()
at MyMovie_fla::MainTimeline/frame40()
I have this for frame 1-39 -
"var clicked:Boolean = false;
button1.addEventListener(MouseEvent.CLICK, goScene2);
function goScene2(event:MouseEvent):void {
clicked = true;
}"
And this for frame 40 -
"if(clicked){
gotoAndPlay(1,"Scene 2");
}
else{
gotoAndPlay(1,"Scene1");
}"
Copy link to clipboard
Copied
"Scene1" is a name I made up for demonstration purposes, you have to exchange it with the name of your actual first scene
Find more inspiration, events, and resources on the new Adobe Community
Explore Now