Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to access variable from within a movieclip code

New Here ,
Jan 17, 2009 Jan 17, 2009
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
TOPICS
ActionScript
787
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 17, 2009 Jan 17, 2009
if parent is the correct path to a, cast it as a movieclip and retry:

MovieClip(parent).a=2;
Translate
Community Expert ,
Jan 17, 2009 Jan 17, 2009
if parent is the correct path to a, cast it as a movieclip and retry:

MovieClip(parent).a=2;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 17, 2009 Jan 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 20, 2023 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2023 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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 20, 2023 May 20, 2023

Thanks so much - for helping me out in this old thread!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2023 May 20, 2023
LATEST

you're welcome 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2023 May 20, 2023

@29821938bjvh 

 

p.s. you're posting to an thread more than 10 years old.

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 17, 2009 Jan 17, 2009
thank you both
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2009 Jan 17, 2009
you're welcome.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines