Skip to main content
Inspiring
June 14, 2009
Question

Accessing Main Timeline Variables from within a MovieClip

  • June 14, 2009
  • 1 reply
  • 1231 views

Hello,

Let us say we have a movieclip "mc1" on the stage.

We also have another movieclip "mc2" inside mc1.

We have declared a variable, say, var number1:Number=5 on the first frame of the main timeline.

Now we go inside mc1 and then inside mc2 and write some code on its first frame.

Is there any way to use the variable number1 over here?

Can properties of mc1 be altered using the code written here?

In AS2, it could be done using the "_parent" command, but it doesn't seem to work in AS3. (when we use parent and try accessing a property, it says that it is possibly undefined)

Thanking You,

Chinmaya

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
June 14, 2009

MovieClip(root).number1

will always work from any timeline in your main swf.

or

MovieClip(this.parent.parent).number1

will work from root.mc1.mc2's timeline

Inspiring
June 14, 2009

Thank You very much.

I was trying to figure this out for a very long time.

I tried searching on the internet, with not too many helpful results.

If its not a problem, can you tell me how this works, or maybe how its different from using "root.mc" or "mc.parent" etc.

Thanks once more,

Chinmaya

kglad
Community Expert
Community Expert
June 14, 2009

there's no difference except you prevent the compiler from generating an error by casting as a movieclip.