• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Forcing Loop Finish

Explorer ,
Mar 03, 2019 Mar 03, 2019

Copy link to clipboard

Copied

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?

Views

329

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Mar 08, 2019 Mar 08, 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 con

...

Votes

Translate

Translate
Community Expert ,
Mar 04, 2019 Mar 04, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 04, 2019 Mar 04, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 05, 2019 Mar 05, 2019

Copy link to clipboard

Copied

Still looking for an answer here~

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

Maybe for you, ShaadeSilentpaw, maybe for others, an alternative solution to letting scenes first finish before navigating to another one.

In Scene 1, frame 1 put this code:

import flash.events.MouseEvent;

import flash.display.Scene;

var anotherScene: String = "no";

this.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(e: MouseEvent):void {

    var etn = e.target.name;

    switch (etn) {

        case "t1":

            anotherScene = "Scene 1";

            break;

        case "t2":

            anotherScene = "Scene 2";

            break;

        case "t3":

            anotherScene = "Scene 3";

            break;

    }

}

function navigateScenes():void {

    var scene: Scene = currentScene;

    if (anotherScene != "no") {

        gotoAndPlay(1, anotherScene);

    } else {

        gotoAndPlay(1, scene.name);

    }

}

This of course assumes you have 3 scenes with those names. Any different situation needs to be adapted accordingly. "t1", "t2" and "t3" are buttons placed in all scenes.

Okay, in every other scene, frame 1, put this to reset the loop behaviour

anotherScene = "no";

and in the last frame of all scenes trigger navigateScenes() with this:

navigateScenes();

Example: Dropbox - scenes_and_loops.zip

Klaus

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

Do the t1/t2/t3 etc represent button instances?

See, my flash has no less than 12 scenes - and all the buttons aren't always supposed to be visible, so they have a lot of different instances. (20-30 or so in total)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2019 Mar 05, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 08, 2019 Mar 08, 2019

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines