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

Help setting up back navigation button by label name.

New Here ,
Mar 03, 2013 Mar 03, 2013

Newbie back for some gems of wisdom.

I am trying to get forward and back buttons to advance the user along the timeline by label name. I got the forward button to work, but can't seem to find the right code tweakage to get the back button to work.

Here is what I have:

stop();

 

var myLabels:Array = [ "A","B","C","D","E","F","G","H" ];

var nextLabel:String;

var inc:int = 1;

var prevLabel:String;

var inc2:int = -1;

 

fwdbtn.addEventListener(MouseEvent.CLICK, clickNextSection);

 

function clickNextSection(e:MouseEvent):void

{

    nextLabel = String(myLabels[inc]);

    gotoAndPlay(nextLabel);

    inc++;

}

 

bkbtn.addEventListener(MouseEvent.CLICK, clickPreviousSection);

 

function clickPreviousSection(e:MouseEvent):void

{

    prevLabel = String(myLabels[inc2]);

    gotoAndPlay(prevLabel);

    inc2++;

}

I'm sure there are some reduncies and I know I'm missing the variable that tells the timeline to subtract positioning from the array.

Do I need to define a new array for the back button?

Any idea what I'm messing up??

Thanks!!

TOPICS
ActionScript
689
Translate
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

LEGEND , Mar 03, 2013 Mar 03, 2013

function clickNextSection(e:MouseEvent):void

{

     inc++;

    if(inc < myLabels.length){

        gotoAndPlay(String(myLabels[inc]));

    } else {

        inc = myLabels.length - 1; // keep it at the end   

    }

}

 

 

function clickPreviousSection(e:MouseEvent):void

{

    inc--;

    if(inc > -1 ){

         gotoAndPlay(String(myLabels[inc]));

    } else {

         inc = 0;  // keep it at the start

    }

}

Translate
LEGEND ,
Mar 03, 2013 Mar 03, 2013

Just use the same inc variable instead of having two and don't increment or decrement it until you are about to use it.  That way it will always reflect where you are instead of where you might be next.

Translate
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
New Here ,
Mar 03, 2013 Mar 03, 2013

Thanks for the reply! Kind of lost unfortunately.

So can you tell me how to edit the code to reflect that? Not sure how what the deincriment syntax and is and not sure how to set it up the way you are suggesting - only adding deincriment/increment on the fly.

Any help you could lend to chopping the code would be appreciated.

Love the logic you suggest. That would ideal for it to work from any point.

Thanks for your help!

Translate
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
LEGEND ,
Mar 03, 2013 Mar 03, 2013

function clickNextSection(e:MouseEvent):void

{

     inc++;

    if(inc < myLabels.length){

        gotoAndPlay(String(myLabels[inc]));

    } else {

        inc = myLabels.length - 1; // keep it at the end   

    }

}

 

 

function clickPreviousSection(e:MouseEvent):void

{

    inc--;

    if(inc > -1 ){

         gotoAndPlay(String(myLabels[inc]));

    } else {

         inc = 0;  // keep it at the start

    }

}

Translate
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
New Here ,
Mar 03, 2013 Mar 03, 2013

Thank you so much!!! It works!! Appreciate your help!

Translate
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
LEGEND ,
Mar 03, 2013 Mar 03, 2013
LATEST

You're welcome

Translate
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