Highlighted

Getting the frame number from frame label in animate cc with HTML5

Community Beginner ,
Sep 15, 2020

Copy link to clipboard

Copied

Hi!

Is there a way to obtain the frame number (say, 30) from a given frame label (say,"myFrame", which is actually the label of frame 30)?

To be more specific, I have the following scenario:

There is a button and an event listener attached to it, using which I want to "gotoAndPlay()" to a particular frame.

However I don't want to use the number of the frame. The frame has a label, say, "myframe".

One way that I have stumbled upon is to use a for loop to find which frame number corresponds to the label, "myframe".

But I would love an easier alternative.

 

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

Try the second option. Like this:

this.gotoAndPlay(this.timeline._labels["myframe"] + 1);

 

Views

85

Likes

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

Getting the frame number from frame label in animate cc with HTML5

Community Beginner ,
Sep 15, 2020

Copy link to clipboard

Copied

Hi!

Is there a way to obtain the frame number (say, 30) from a given frame label (say,"myFrame", which is actually the label of frame 30)?

To be more specific, I have the following scenario:

There is a button and an event listener attached to it, using which I want to "gotoAndPlay()" to a particular frame.

However I don't want to use the number of the frame. The frame has a label, say, "myframe".

One way that I have stumbled upon is to use a for loop to find which frame number corresponds to the label, "myframe".

But I would love an easier alternative.

 

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

Try the second option. Like this:

this.gotoAndPlay(this.timeline._labels["myframe"] + 1);

 

Views

86

Likes

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
Sep 15, 2020 0
Adobe Community Professional ,
Sep 15, 2020

Copy link to clipboard

Copied

Hi.

 

You can just pass the label name to the gotoAndPlay method like this:

 

this.gotoAndPlay("myframe");

 

 

Or if you really need the frame of the first frame of the label there is an undocumented array property of the timeline object called _labels. You can use it to easily get the corresponding frame number. Like this:

 

this.gotoAndPlay(this.timeline._labels["myframe"]);

 

 

Please let us know if this is what you want.

 

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Sep 15, 2020 1
Community Beginner ,
Sep 15, 2020

Copy link to clipboard

Copied

Thanks for the reply. However I am aware of the option of using gotoAndPlay("myframe"). To be precise, I want something like gotoAndPlay ("myframe"-1);

 

Likes

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
Reply
Loading...
Sep 15, 2020 0
Adobe Community Professional ,
Sep 15, 2020

Copy link to clipboard

Copied

Try the second option. Like this:

this.gotoAndPlay(this.timeline._labels["myframe"] + 1);

 

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Sep 15, 2020 1
Community Beginner ,
Sep 15, 2020

Copy link to clipboard

Copied

Exactly. Thank you so much!!

Likes

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
Reply
Loading...
Sep 15, 2020 1
Adobe Community Professional ,
Sep 15, 2020

Copy link to clipboard

Copied

Excellent! You're welcome!

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Sep 15, 2020 0
Community Beginner ,
Sep 15, 2020

Copy link to clipboard

Copied

Hey it's solved. Thank you so much.

I just used console.log(this.timeline._labels["myframe"]); following your suggestion. Works like a charm!

Likes

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
Reply
Loading...
Sep 15, 2020 1