# Back button that takes you to the last Scene visited

**URL:** <https://forum.kirupa.com/t/back-button-that-takes-you-to-the-last-scene-visited/34152>\
**Category:** flash\
**Created:** [October 28, 2003, 8:32pm UTC](https://forum.kirupa.com/t/back-button-that-takes-you-to-the-last-scene-visited/34152 "2003-10-28T20:32:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cobaltblue](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cobaltblue](https://forum.kirupa.com/u/cobaltblue)\
**Post date:** [October 28, 2003, 8:32pm UTC](https://forum.kirupa.com/t/back-button-that-takes-you-to-the-last-scene-visited/34152/1 "2003-10-28T20:32:18Z")

</div>

Hello Kirupa forum,

First off, i just want to say that I’m pretty much a newbie when it comes to Flash MX ActionScript.

Okay, here here’s my situation…

I just created a Flash MX document with 10 scenes.

I have included a menu that will take the user to any of the 10 scenes. Moreover, in each of these 10 scenes, I added a BACK, NEXT, and HOME button for navigation purposes.

My problem is this…

I was at ‘Scene 1’ and I wanted to jump to ‘Scene 7’, so I go to my menu and clicked on the button that would take me to ‘Scene 7’.

Okay…now that I’m at ‘Scene 7’ I want to go back to ‘Scene 1’. BUT THIS TIME I WANT TO USE MY NAVIGATION BUTTONS.

So I press the BACK button from ‘Scene 7’ and it takes me to ‘Scene 6’. (I already know why it took me to ‘Scene 6’ instead of ‘Scene 1’.) BUT, I WANTED IT TO GO BACK TO THE LAST SCENE VISITED!

So my question is this…

How do you get FLASH MX to remember which Scene you last visited?

Is there a script that I must add to force it to remember the last scene visited?

thank you Kirupaforum,  
cobaltblue

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 30, 2003, 12:51am UTC](https://forum.kirupa.com/t/back-button-that-takes-you-to-the-last-scene-visited/34152/2 "2003-10-30T00:51:21Z")

</div>

I believe that it can be done by setting up a var.

in scene 1 set up vars

back = HOME  
next = SCENE2  
home = HOME

and a var for each of your 10 scenes.

when you click on a button next you change the vars.

So in your example…  
you click on the scene 7 button and change the vars to…

back = HOME  
next = SCENE8  
home = HOME

hence now when you click the back button you will be taken back to home, instead of scene 6…

hope this helps

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 30, 2003, 4:26am UTC](https://forum.kirupa.com/t/back-button-that-takes-you-to-the-last-scene-visited/34152/3 "2003-10-30T04:26:20Z")

</div>

I have a slightly different answer.

Set up a variable on your main timeline… something like:

[AS]var lastplayed=“one”[/AS]

Then, your buttons could be setup this way…

[AS]  
mybutton1.onRelease=function(){  
\_root.lastplayed=“one”;  
//put the rest of your code here  
}

mybutton2.onRelease=function(){  
\_root.lastplayed=“two”;  
//put the rest of your code here  
}  
[/AS]

Then, you could simply set up your back button to say something like:

[AS]  
backbutton.onRelease=function(){  
gotoandplay(\_root.lastplayed);  
}  
[/AS]

btw, all the code I have included would be placed in a single frame on the MAIN TIMELINE, not on the objects (buttons) themselves.

I hope this at least provides you with some of the logic behind coding something like that.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 30, 2003, 4:40am UTC](https://forum.kirupa.com/t/back-button-that-takes-you-to-the-last-scene-visited/34152/4 "2003-10-30T04:40:21Z")

</div>

you have to love functions…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 30, 2003, 4:52am UTC](https://forum.kirupa.com/t/back-button-that-takes-you-to-the-last-scene-visited/34152/5 "2003-10-30T04:52:56Z")

</div>

functions are your friends.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 30, 2003, 8:23am UTC](https://forum.kirupa.com/t/back-button-that-takes-you-to-the-last-scene-visited/34152/6 "2003-10-30T08:23:02Z")

</div>

yes, functions are you friends, but they i would do this would be without any functions at all.

i love to use \_global.variables in my works. So much easier to contact. SOOOO … a script ON a button would be like yours, Inigo, Whatever button you click, the Global variable:

\_global.lastPlace

gets set to that, and the “lastPlace” would be where your back button would take you.
