Skip to main content
tazkerah
Known Participant
June 10, 2020
Answered

can we get the current frame label?

  • June 10, 2020
  • 2 replies
  • 2350 views

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?

 

 

This topic has been closed for replies.
Correct answer JoãoCésar17023019

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:

https://bit.ly/2XQr6Po

 

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:

https://github.com/joao-cesar/adobe/tree/master/animate%20cc/html5_canvas/navigate_from_label_to_label

 

I hope this helps.

 

Regards,

JC

2 replies

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
June 11, 2020

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:

https://bit.ly/2XQr6Po

 

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:

https://github.com/joao-cesar/adobe/tree/master/animate%20cc/html5_canvas/navigate_from_label_to_label

 

I hope this helps.

 

Regards,

JC

tazkerah
tazkerahAuthor
Known Participant
June 12, 2020

It works! obrigado

Legend
June 10, 2020

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.

tazkerah
tazkerahAuthor
Known Participant
June 11, 2020

"you should just have a global variable that tracks the current frame label number."

and how to do that?