Skip to main content
Participant
Jan 17, 2009 5:14 PM UTC
Answered

How to access variable from within a movieclip code

i have variable a=0 and i want a movieclip that runs to change it to 2, what do i write in the movieclip code ?
i tried parent.a=2 but it's error.
thanks
This topic is closed to new replies. Start a new post to keep the conversation going.
kglad
kgladCorrect answer
Community Expert
Jan 17, 2009 5:45 PM UTC
if parent is the correct path to a, cast it as a movieclip and retry:

MovieClip(parent).a=2;

9 replies

kglad
Community Expert
Community Expert
Jan 17, 2009 6:51 PM UTC
you're welcome.
Translate
SuperjetsAuthor
Participant
Jan 17, 2009 6:04 PM UTC
thank you both
Translate
robdillon
Participating Frequently
Jan 17, 2009 5:47 PM UTC
Where is a in relation to the movieClip? Are they both attached to the same display object? If that's the case, then the path will be a = 2. If the variable is attached to a parent display object then the path may be MovieClip(parent).a = 2.
Translate
Participant
May 20, 2023 12:11 PM UTC

I assume "MovieClip" is the instance name of the movie clip right? What if there is no instance name, because I have placed 200 of the same movieclip on stage manually? But I would like to access the variable on the root level / main timeline. How would the code look like?

Translate
kglad
Community Expert
Community Expert
May 20, 2023 1:11 PM UTC

MovieClip is not an instance and cannot be an instance name (or anything other than an adobe defined class) and is a reserved word.  in my first post here i used it to coerce animate into understanding parent was a movieclip.  otherwise, the compiler might think there's an error.

 

in as3, the root timeline can always be referenced by,

 

root

 

and, for some things you may need to cast it as a movieclip (assuming it is one)

 

MovieClip(root)

Translate
kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
Jan 17, 2009 5:45 PM UTC
if parent is the correct path to a, cast it as a movieclip and retry:

MovieClip(parent).a=2;
Translate