Understanding _root and _parent is crucial if you want to easily change properties of your symbols via Actionscript. To explain how they work, let's get straight to an example:
For the sake of this tutorial, we'll assume that these 3 objects have identical instance names assigned. |
So, I now have a question for you: if you were inside object3, how would you specify a reference to object?
Both _root and _parent would be OK to use here.
I will now change the x property of the object using Actionscript.
- // _root method
- _root.object1._x = 200;
- // _parent method
- _parent._parent.object1._x = 200;
As I said, both of these lines will do the job. Nevertheless, the _root method is easier to remember and harder to make a mistake with.
You might have already figured that out, but let me state what _root and _parent do:
_parent tells Flash to start reading from one level up. Because in the example object1 is two levels higher than object3, we must use _parent twice. Whereas _root specifies a reference to the main stage. So, you might say that _root is absolute, while _parent is relative.
OK. That's pretty much it. Here you can find more tutorials.
Thanks for reading,
Cheers!
