Noah R
Noah R

Reputation: 5477

How to use variables from main timeline in moveclip timelines?

I have some main time line variables I need to access and manipulate from inside a movieclip timeline. However, when I try to subtract from a global variable, one that's declared on the main timeline on frame 1 outside of a function/whatever, it says: Symbol 'lemon_cup', Layer 'actions', Frame 1, Line 54 1120: Access of undefined property lemons1.

So how can I "import" this variable and make it accessible and useful inside of a moveiclip's timeline?

Upvotes: 1

Views: 2517

Answers (1)

roberttdev
roberttdev

Reputation: 46513

First, do you have an ActionScript class defined as your document class? You should go ahead and do that and make sure your variable is defined there. Make sure it's public (or have a public accessor function). That way the variable value exists outside of the particular part of the timeline where it's defined (which means its existence can come and go).

Then, anywhere in any timeline script where you want to access the variable, get a reference to "root" which will return your linked document object. You can then access the variable's value through that object:

var myVarCopy:Number = MyDocumentClass(root).myVar;

Hope this helps.

Upvotes: 2

Related Questions