PDA

View Full Version : Accessing a variable from a movieclip


jporter313
05-05-2008, 09:22 PM
I am trying to set up a variable in my main timeline that I can access from movieclips. However this doesn't seem to be working for some reason. Here's the code that instantiates the variable in the first frame of my main timeline:

var leftTextVar:int = 0;

here's the code within a movieclip that I'm trying to use to access it:

LeftText.text = String(leftTextVar);

When I run this, I get this error:

1120: Access of undefined property leftTextVar.

So can anyone tell me why this isn't working?

jporter313
05-06-2008, 03:01 AM
Anyone?

scienceninja
05-06-2008, 02:12 PM
seems like a similar problem as this one:
http://www.actionscript.org/forums/showthread.php3?t=169706

What I've done is set a reference to the root, of if there's a main document class, have it send a reference to itself to any lnstantiated movieclips. basically this:



var rootref:Object = root;
LeftText.text = String(rootref.leftTextVar);



To be honest, i'm not sure if this is the best way but it works for me.

jporter313
05-07-2008, 01:08 AM
Thanks, Scienceninja, I'll try this.