Skip to main content
InsertNameHere9960
Participant
June 2, 2021
Answered

Variable undefined, despite being defined in separate nested animation.

  • June 2, 2021
  • 1 reply
  • 713 views

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.

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

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";

 

1 reply

JoãoCésar17023019
Community Expert
Community Expert
June 2, 2021

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

InsertNameHere9960
Participant
June 2, 2021

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?

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
June 2, 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";