Copy link to clipboard
Copied
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!!
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
}
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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
}
}
Copy link to clipboard
Copied
Thank you so much!!! It works!! Appreciate your help!
Copy link to clipboard
Copied
You're welcome
Find more inspiration, events, and resources on the new Adobe Community
Explore Now