Copy link to clipboard
Copied
hello! I am trying to make universal next and previous button that navigate between labeled frame
if the first frame labeled with the label "1" (the label is "1") and the seconed is "2" and etc.
if i can get the current frame label then i can use the current farme label +1, and the previous button current farme label -1
or is there another way?
Hi.
You can use the labels array property that stores the labels names and their corresponding frames. Then you can increment and decrement a counter variable to keep track of which array item to access. Like this:
Preview:
JavaScript code:
var root = this;
var labels = root.labels;
var index = 0;
root.start = function()
{
root.gotoPrevLabel = function(e)
{
index = root.clamp(--index, 0, labels.length - 1);
root.gotoAndStop(labels[index].position);
};
root.
...
Copy link to clipboard
Copied
If these buttons are the only way to move between frames, you should just have a global variable that tracks the current frame label number.
Also, you should absolutely not use numbers as frame labels. That's just begging Animate to get confused whether you're asking it to go to a frame number or a frame label.
Copy link to clipboard
Copied
"you should just have a global variable that tracks the current frame label number."
and how to do that?
Copy link to clipboard
Copied
Hi.
You can use the labels array property that stores the labels names and their corresponding frames. Then you can increment and decrement a counter variable to keep track of which array item to access. Like this:
Preview:
JavaScript code:
var root = this;
var labels = root.labels;
var index = 0;
root.start = function()
{
root.gotoPrevLabel = function(e)
{
index = root.clamp(--index, 0, labels.length - 1);
root.gotoAndStop(labels[index].position);
};
root.gotoNextLabel = function(e)
{
index = root.clamp(++index, 0, labels.length - 1);
root.gotoAndStop(labels[index].position);
};
root.on("click", function(e)
{
if (e.target.name === "prevButton")
root.gotoPrevLabel();
else if (e.target.name === "nextButton")
root.gotoNextLabel();
});
root.stop();
};
root.clamp = function(value, min, max)
{
if (value < min)
return min;
if (value > max)
return max;
return value;
};
if (!root.frame0Started)
{
root.start();
root.frame0Started = true;
}
FLA / source / files:
I hope this helps.
Regards,
JC
Copy link to clipboard
Copied
It works! obrigado
Copy link to clipboard
Copied
Hi, there is a small issue. I originaly had in the verey first frame a small script, stop [this.stop();] and a play button [playBtn on click; gotoAndPlay(currentFrame + 1); ] and they used to work but not now, I think when redifined [this] something happend,
so if you can please add to the code a third button [playBtn] wich on click of any instant of it just play the time line.
another issue, in which line should I add stop sound functionality to the next and previous button
Regards.