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

How to make a back button?

Guest
Jul 27, 2012 Jul 27, 2012

Copy link to clipboard

Copied

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.

TOPICS
ActionScript

Views

1.3K

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

Enthusiast , Jul 27, 2012 Jul 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())

Votes

Translate

Translate
Enthusiast ,
Jul 27, 2012 Jul 27, 2012

Copy link to clipboard

Copied

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())

}

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
Guest
Jul 27, 2012 Jul 27, 2012

Copy link to clipboard

Copied

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"?

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
Enthusiast ,
Jul 27, 2012 Jul 27, 2012

Copy link to clipboard

Copied

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())

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
Guest
Aug 14, 2012 Aug 14, 2012

Copy link to clipboard

Copied

Ok I have a problem with the back button.

Example frame 1, frame 2, frame 3, frame 4, frame 5

I start at frame 1 and go to 2, 3, 4, and then 5. It will only let me go back to frame 2. So if I start going forward again from frame 2 and go to 3, 4, and then 5. I can only go back to frame 3.

I think the problem is it removes the frames before entering the current frame. How do I fix this?

Thanks in advance - John

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
Enthusiast ,
Aug 14, 2012 Aug 14, 2012

Copy link to clipboard

Copied

You are not using the same code above,  can you show your code?

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
Guest
Aug 14, 2012 Aug 14, 2012

Copy link to clipboard

Copied

stop();

var myBackList:Array=new Array();

bioBut.addEventListener(MouseEvent.CLICK, gotoBiographies);

overviewBut.addEventListener(MouseEvent.CLICK, gotoOverview);

commemorationBut.addEventListener(MouseEvent.CLICK, gotoCommemoration);

GettingStartedButt.addEventListener(MouseEvent.CLICK, gotoAboutTheLesson);

myBackButton.addEventListener(MouseEvent.CLICK, goBack);

function gotoBiographies(event:MouseEvent):void

{

    gotoAndStop("bios");

    myBackList.push("bios");

}

function gotoOverview(event:MouseEvent):void

{

    gotoAndStop("overview");

    myBackList.push("overview");

}

function gotoCommemoration(event:MouseEvent):void

{

    gotoAndStop("commemorationFrame");

    myBackList.push("commemorationFrame");

}

function gotoAboutTheLesson(event:MouseEvent):void

{

    gotoAndStop("aboutTheLesson");

    myBackList.push("aboutTheLesson");  

}

function goBack(e:MouseEvent):void

{

    gotoAndStop(myBackList.pop());

}

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
Enthusiast ,
Aug 14, 2012 Aug 14, 2012

Copy link to clipboard

Copied

stop();

var myBackList:Array=new Array();

bioBut.addEventListener(MouseEvent.CLICK, gotoBiographies);

overviewBut.addEventListener(MouseEvent.CLICK, gotoOverview);

commemorationBut.addEventListener(MouseEvent.CLICK, gotoCommemoration);

GettingStartedButt.addEventListener(MouseEvent.CLICK, gotoAboutTheLesson);

myBackButton.addEventListener(MouseEvent.CLICK, goBack);

function gotoBiographies(event:MouseEvent):void {

    gotoAndStop("bios");

    myBackList.push("bios");

    trace(myBackList)

}

function gotoOverview(event:MouseEvent):void {

    gotoAndStop("overview");

    myBackList.push("overview");

    trace(myBackList)

}

function gotoCommemoration(event:MouseEvent):void {

    gotoAndStop("commemorationFrame");

    myBackList.push("commemorationFrame");

    trace(myBackList)

}

function gotoAboutTheLesson(event:MouseEvent):void {

    gotoAndStop("aboutTheLesson");

    myBackList.push("aboutTheLesson");

    trace(myBackList)

}

function goBack(e:MouseEvent):void {

    trace(myBackList);

    var frameGo:String=myBackList.pop();

    (currentLabel==frameGo)?gotoAndStop(myBackList.pop()):gotoAndStop(frameGo);

    trace(myBackList);

    trace("---------");

}

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
Guest
Aug 15, 2012 Aug 15, 2012

Copy link to clipboard

Copied

LATEST

Thanks for your help, kglad came up with a slightly different solution with booleans. Again thank you for your help. Heres what he came up with:

stop();

var myBackList:Array=new Array();

var backFrame:*;

var forwardFrame:* = 1;

var addForwardBool:Boolean = false;

var addBackBool:Boolean = false;

myBackList.push(1);

bioBut.addEventListener(MouseEvent.CLICK, gotoBiographies);

overviewBut.addEventListener(MouseEvent.CLICK, gotoOverview);

commemorationBut.addEventListener(MouseEvent.CLICK, gotoCommemoration);

GettingStartedButt.addEventListener(MouseEvent.CLICK, gotoAboutTheLesson);

function gotoBiographies(event:MouseEvent):void

{

    addForwardBool=true;

    addFrameF();

    forwardFrame="bios";

    gotoAndStop("bios");

}

function gotoOverview(event:MouseEvent):void

{

    addForwardBool=true;

    addFrameF();

    forwardFrame="overview";

    gotoAndStop("overview");

}

function gotoCommemoration(event:MouseEvent):void

{

    addForwardBool=true;

    addFrameF();

    forwardFrame="commemorationFrame";

    gotoAndStop("commemorationFrame");

}

function gotoAboutTheLesson(event:MouseEvent):void

{

    addForwardBool=true;

    addFrameF();

    forwardFrame="aboutTheLesson";

    gotoAndStop("aboutTheLesson");

}

function goBack(e:MouseEvent):void

{

    backFrame=myBackList.pop();

    if(backFrame)

    {

        addBackBool=true;

        gotoAndStop(backFrame);

    }

}

function addFrameF():void

{

    if (forwardFrame && addForwardBool)

    {

        myBackList.push(forwardFrame);

    }

    if (backFrame && addBackBool)

    {

        myBackList.push(backFrame);

    }

    addBackBool=false;

    addForwardBool=false;

}

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