Variable undefined, despite being defined in separate nested animation.

Community Beginner ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

I have a variable, which I defined in my first nested animation, and I want to access it in my second nested animation, however animate says that it is undefined. I think that it won't allow me to reference the variable since it's not used in the same nested animation as when it is defined. Any help would be appreciated.

TOPICS
ActionScript

Views

193

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
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Jun 02, 2021 Jun 02, 2021
Oh. I'm really sorry. My explanation is for HTML5 documents. In AS3, declare your variables in the main timeline and then reference them from anywhere like this: MovieClip(root).yourVariable = "something";

Likes

Translate

Translate
Adobe Community Professional ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

Hi.

 

Variables are only available in the frame in which they were declared.

 

For persistent values over more than one frame, you need to use properties.

 

For example: create a property on the main timeline called value0 like this:

this.value0 = "something";

 

Then you can access it from anywhere like this:

console.log(exportRoot.value0); // exportRoot is a global variable that refers to the main timeline and it's created automatically in the publishing process

 

Hope this helps and don't hesitate to ask if you have any further questions.

 

Regards,
JC

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
community guidelines
Community Beginner ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

Thanks for taking the time to reply. I'm currently getting an error which states that 'console' and 'exportRoot' are undefined. Is there any way I can fix this?

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
community guidelines
Adobe Community Professional ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

Oh. I'm really sorry.

 

My explanation is for HTML5 documents.

 

In AS3, declare your variables in the main timeline and then reference them from anywhere like this:

MovieClip(root).yourVariable = "something";

 

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
community guidelines
Community Beginner ,
Jun 03, 2021 Jun 03, 2021

Copy link to clipboard

Copied

This fixed the issue. 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
community guidelines
Adobe Community Professional ,
Jun 03, 2021 Jun 03, 2021

Copy link to clipboard

Copied

LATEST

Great! You're welcome!

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
community guidelines