Skip to main content
Inspiring
March 4, 2019
Answered

Forcing Loop Finish

  • March 4, 2019
  • 3 replies
  • 590 views

So, I have a flash file set up with several looping scenes and buttons that allow the users to jump back and forth between scenes.

Say the user clicks a button to jump to a new scene while in the middle of another one - is there a way to make sure the current loop will always run to it's end before switching to the new one, rather than immediately jumping to it as soon as the button is clicked?

This topic has been closed for replies.
Correct answer kdmemory

Yes, t1, t2 and t3 are button instances.

I'm not sure, what you precisely mean with "so they have a lot of different instances. (20-30 or so in total)". But if you have 12 scenes and - at least maximally 12 button instances, they don't need to be all present in all scenes. Just place those into scenes which link to scenes you want to enable a user to get to in any given situation. If certain scene-buttons are not present, they can't be clicked and the associated scenes can't be reached.

In the concept I suuggested above you only must make sure that each scene has a dedicated button instance/name and that they are all prescribed in the central clickHandler().

Klaus

3 replies

kdmemory
kdmemoryCorrect answer
Inspiring
March 8, 2019

Yes, t1, t2 and t3 are button instances.

I'm not sure, what you precisely mean with "so they have a lot of different instances. (20-30 or so in total)". But if you have 12 scenes and - at least maximally 12 button instances, they don't need to be all present in all scenes. Just place those into scenes which link to scenes you want to enable a user to get to in any given situation. If certain scene-buttons are not present, they can't be clicked and the associated scenes can't be reached.

In the concept I suuggested above you only must make sure that each scene has a dedicated button instance/name and that they are all prescribed in the central clickHandler().

Klaus

JoãoCésar17023019
Community Expert
Community Expert
March 5, 2019

Hi.

One approach you can follow is to have a variable to store the next scene you want to navigate to and then in the last frame of each scene you call the gotoAndStop method passing the value of that variable.

Here is an example with 3 buttons and 3 scenes.

AS3 code:

[Scene 1]

Frame 1

import flash.events.MouseEvent;

var destination:String;

function setScene1(e:MouseEvent):void

{

    destination = "Scene 1";

    play();

}

function setScene2(e:MouseEvent):void

{

    destination = "Scene 2";

    play();

}

function setScene3(e:MouseEvent):void

{

    destination = "Scene 3";

    play();

}

stop();

scene1Button.addEventListener(MouseEvent.CLICK, setScene1);

scene2Button.addEventListener(MouseEvent.CLICK, setScene2);

scene3Button.addEventListener(MouseEvent.CLICK, setScene3);

Frame 120 (the last one)

gotoAndStop(1, destination);

[Scene 2]

Frame 1

import flash.events.MouseEvent;

scene1Button.addEventListener(MouseEvent.CLICK, setScene1);

scene2Button.addEventListener(MouseEvent.CLICK, setScene2);

scene3Button.addEventListener(MouseEvent.CLICK, setScene3);

Frame 120 (the last one)

gotoAndStop(1, destination);

[Scene 3]

Frame 1

import flash.events.MouseEvent;

scene1Button.addEventListener(MouseEvent.CLICK, setScene1);

scene2Button.addEventListener(MouseEvent.CLICK, setScene2);

scene3Button.addEventListener(MouseEvent.CLICK, setScene3);

Frame 120 (the last one)

gotoAndStop(1, destination);

FLA download:

animate_cc_as3_navigate_scenes.zip - Google Drive

I hope this helps.

Regards,

JC

Michael Bullo
Community Expert
Community Expert
March 4, 2019

Could you make it so that clicking a button sets a variable instead of immediately jumping to another scene? At the end each scene you could test the value of this variable and either repeat the current scene or jump to another scene.

Inspiring
March 4, 2019

Hmm, how would that look in AS3 code though?

Should've mentioned I'm a complete newbie to all of this and hopeless when it comes to scripting

Inspiring
March 5, 2019

Still looking for an answer here~