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

How to access variable from within a movieclip code

New Here ,
Jan 17, 2009 Jan 17, 2009

Copy link to clipboard

Copied

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

Views

580

Translate

Translate

Report

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;

Votes

Translate

Translate
Community Expert ,
Jan 17, 2009 Jan 17, 2009

Copy link to clipboard

Copied

if parent is the correct path to a, cast it as a movieclip and retry:

MovieClip(parent).a=2;

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

you're welcome 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

@29821938bjvh 

 

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

 

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

thank you both

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

you're welcome.

Votes

Translate

Translate

Report

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