Skip to main content
July 27, 2012
Answered

How to make a back button?

  • July 27, 2012
  • 1 reply
  • 1559 views

I want to make a back button, but I'm not really sure how to do this. I did some research and some people said you need an array. I've never made an array before. Everyone of my frames have a label and multiple ways to get to that frame. Can anyone help me with this? Any help would be appreciated, thank you.

This topic has been closed for replies.
Correct answer esdebon

yes, you must add to each button, the array is a stack and added in the order they arrive, to "back" you will always take the last.

The pop method, gets the last value and delete it

gotoAndStop(myBackList.pop())

1 reply

esdebon
Inspiring
July 27, 2012

The array will be a list of your steps

define the array:

var myBackList:Array=new Array();

now every time it you change to another frame, add to the list (array) the label name of the frame

i.e.

myButtonGoToFirstSection.addEventListener(MouseEvent.CLICK, gotoFirstSection)

function gotoFirstSection(e:MouseEvent):void{

         gotoAndStop("FirstSeccion")

          myBackList.push("FirstSeccion") //this add the the label to the array

}

then the code to the back button is:

myBackButton.addEventListener(MouseEvent.CLICK, goBack)

function goBack(e:MouseEvent):void{

          gotoAndStop(myBackList.pop())

}

July 27, 2012

So I have to add this  myBackList.push("FirstSeccion") to everyone of my buttons. How does it know the order of the frames in the array? And does it remove them from the array when call upon or overwritten with "myBackButton"?

esdebon
esdebonCorrect answer
Inspiring
July 27, 2012

yes, you must add to each button, the array is a stack and added in the order they arrive, to "back" you will always take the last.

The pop method, gets the last value and delete it

gotoAndStop(myBackList.pop())