AS2 vs. AS3: _root or .parent- Communicating Between SWFs

ok, so climbing up your hierarchy tree was soooooo easy in AS2. But, of course, in AS3 it isn’t easy at all.

Let’s say my master movie loads in an external SWF. OK, I’m chillin and hangin out writin my code in my external SWF when BAM!!!! All of a sudden i need some info or to call a function i already wrote in my master movie.

In AS2 you would do this:
_root.onOff = true; //changes the onOff variable in master to true;
_root.subMenuOnOff(); //calls my subMenuOnOff() function in the master;

In AS3 you do this:
MovieClip(this.parent.parent).onOff = true;
MovieClip(this.parent.parent).subMenuOnOff();
//this is bascially saying, i want to go to this object’s parent(loader), then i want to go to the loader’s parent (root timeline), and BTW the root timeline in a movieclip. I’m not sure why i have to tell you that when you can’t be anything other then a movieclip, but ahhhhhhh the beauty of as3!

The first .parent is my loader and the second call to .parent is actually the SWF’s root timeline. The master displayObject is always a movieclip and isn’t a sealed class. If you’re using Sprites…you’re gonna run into some trouble. Maybe you could typecast to work around it but I’m giving no promises because i haven’t tried it.

Moral of the Story: ok, so you at least always need 2 calls to parents. (.parent.parent) one parent is the loader you used and the other is the main timeline.

OHHHHH, so you’re loading your external SWF into a movieClip are ya? In that case, just add one more .parent.

Hope that helps!

Note: The “mother ship”, master timeline, _root, etc is ALWAYS A MOVIECLIP.