Hierarchy
Root
Root – is a main timeline of the movie. Everything which is placed on the main timeline belongs to the root. To refer to the root in the code we use the following notation _root .
Through the _root we may refer to Actions (which are root methods), such as play(), goToAndPlay(…) and others, main movie properties, such as _totalframes and others. Also it's possible to refer by name to all movie clips that are placed on the main timeline like for example root.myMovie._xscale .
No when you know that you may return to our previous “Kill the bug” project where we created an “anchor” symbol to read a relative mouse position and discard this anchor. You may simply refer to the _root. _ xmouse when you need. It will count mouse position from the left top corner of the screen.
If in the root hierarchy you have a nested movie symbols you may refer to them step by step. So called dot notation used in Flash makes it possible. For example to manipulate the toe of the animated man on the stage it could be something like that _root.mvMan.mvLeg.mvToe.play(); It is presumed that leg is nested inside the man movie symbol and toe nested inside the leg movie symbol.
Let's create a small example
- Create a file with a button and 6 dynamic text fields. Assign variables to all text fields in var box of Properties Inspector. Those variables may be maintotal, mainframe, balltotal, ballframe, lighttotal, lightframe
- Create a movie symbol of the ball and nest inside the ball a movie symbol of the light flicker. Drag ball on the stage and give a ball instance name “ball”. Double click ball highlight a “flicker” symbol and give it also an instance name … “light”
- Enter the following code in the button event handler
on(press) { maintotal=_root._totalframes; mainframe=_root._currentframe; balltotal=_root.ball._totalframes; ballframe=_root.ball._currentframe; lighttotal=_root.ball.light._totalframes; lightframe=_root.ball.light._currentframe; }You may see that first two text variable refer to the properties of the main timeline. Next two –refer to properties of the ball instance placed on the timeline. The last two text variables are connected to the light instance, which is inside the ball instance.
- Test the movie. When button is clicked three textboxes must show the value of the total frames for the main timeline, and both symbols. They will be always the same. Other textboxes displays the frame where timeline and both symbols were at the moment of clicking. They will be updated every time you clicked the button.