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.
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";
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
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?
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";
Copy link to clipboard
Copied
This fixed the issue. Thank you so much.
Copy link to clipboard
Copied
Great! You're welcome!