If you are working with multiple layers of MovieClips, each with their own ActionScript (trust me, with dynamic projects, you can end up in a situation where MovieClips have minds actions of their own) you might come across a situation where you need to access a variable or another MovieClip from the MovieClip that owns it (as in it’s parent) or even two or more above. (If you need to skip all the nested MCs and access a variable on the now-depricated _root read this article)
This is actually quite easy with a method called parent, utilizing the hierarchy of your MovieClips to access variables from any number of levels away from your current execution realm.
To access a variable – let’s call it myVariable – from one level up in your tree, use this:
trace( MovieClip( parent ).myVariable );
Similarly, to access a variable two or more MovieClips up in the tree, nest the parent calls accordingly.
trace( MovieClip( parent.parent ).myVariable );
You can do this ad-infinitum to the root of the whole project if you so desire, but in this case, again, I’d recommend that you read the article mentioned above.
To access other MovieClips, the process is very much the same, except instead of a variable name, you would use a MovieClip’s Instance Name followed by the property you wanted to adjust, as such:
MovieClip( parent ).myMovieClip.visible = true;
-or-
MovieClip( parent.parent.parent ).myMovieClip.gotoAndStop( 1 );
etc.
Hope this helps someone,
Cheers,
~/A\V/
Recent Comments