Skip to main content
Participant
January 17, 2009
Answered

How to access variable from within a movieclip code

  • January 17, 2009
  • 4 replies
  • 875 views
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 has been closed for replies.
Correct answer kglad
if parent is the correct path to a, cast it as a movieclip and retry:

MovieClip(parent).a=2;

4 replies

kglad
Community Expert
Community Expert
January 17, 2009
you're welcome.
SuperjetsAuthor
Participant
January 17, 2009
thank you both
robdillon
Participating Frequently
January 17, 2009
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.
Participant
May 20, 2023

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?

kglad
Community Expert
Community Expert
May 20, 2023

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)

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
January 17, 2009
if parent is the correct path to a, cast it as a movieclip and retry:

MovieClip(parent).a=2;