Vijay Bagul
Vijay Bagul

Reputation: 237

How to access variable of parent movie clip in Action script 3.0

How to access variable of parent movie clip in child movie clip in Action script 3.0

Thanks.

Upvotes: 3

Views: 5117

Answers (1)

Marty
Marty

Reputation: 39466

Same way you would access a variable of any object, using parent as the target object. Because the parent property is of type DisplayObjectContainer, you will need to cast it to MovieClip like so:

trace((parent as MovieClip).myvar);

The reason for the need to cast to MovieClip is that it is dynamic, meaning you won't get compile-time errors for attempting to access properties that the compiler doesn't know about.

Upvotes: 4

Related Questions