Skip to main content
Participant
October 24, 2013
Answered

SCENES BACK BUTTON

  • October 24, 2013
  • 1 reply
  • 610 views

I did a search on this and didn't find a successful answer yet.

I need to have a back button in AS3 that'll remember the last SCENE visited from any frame in the site. There are various buttons to get to various SCENES, and the one back button will always be showing.

What's the script to make that happen from any frame utilizing AS3?

This topic has been closed for replies.
Correct answer kglad

you should execute the following once:

var sceneA:Array = [];

function addSceneF(scene:Scene):void{

    sceneA.push(scene);

}

function prevSceneF():void{

    sceneA.pop();

    this.gotoAndStop(1,sceneA.pop().name);

}

// then on frame 1 of each scene use:

addSceneF(this.currentScene);

and have your previous scene button call prevSceneF whenever you want to return to a previously visited scene.

(and you should do some error checking to make sure sceneA.length >0 before applying that goto.)

1 reply

kglad
Community Expert
Community Expert
October 24, 2013

you'll need to track (use an array) the scenes visited.  then use the pop method twice (the first time will be the current scene) to retrieve the previously visited scene.

Participant
October 24, 2013

Tell me more about this pop method...

I'm trying this code:

var backValue:String;

backValue ="SCENE_NAME";

function backFunction(e:MouseEvent):void {

gotoAndStop(backValue);

}

But, it isn't working... this is the error: "ArgumentError: Error #2109: Frame label SCENE_NAME not found in scene CURRENT_SCENE."

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
October 24, 2013

you should execute the following once:

var sceneA:Array = [];

function addSceneF(scene:Scene):void{

    sceneA.push(scene);

}

function prevSceneF():void{

    sceneA.pop();

    this.gotoAndStop(1,sceneA.pop().name);

}

// then on frame 1 of each scene use:

addSceneF(this.currentScene);

and have your previous scene button call prevSceneF whenever you want to return to a previously visited scene.

(and you should do some error checking to make sure sceneA.length >0 before applying that goto.)