Working with Movie Clips and Buttons > About multiple Timelines > About absolute and relative target paths

 

About absolute and relative target paths

You can use actions to send messages from one Timeline to another. The Timeline that contains the action is called the controlling Timeline, and the Timeline that receives the action is called the target Timeline. For example, there could be an action on the last frame of one Timeline that tells another Timeline to play. To refer to a target Timeline, you must use a target path, which indicates the location of a movie clip in the display list.

The display list of movie clips in authoring mode
 

The hierarchy of movie clips in this display list is as follows:

_level0
		westCoast
				california
						sanfrancisco
						bakersfield
				oregon
						portland
						ashland
				washington
						olympia
						ellensburg

Just as on a Web server, each Timeline in Flash can be addressed in two ways: with an absolute path or a relative path. The absolute path of an instance is always a full path from a level name, regardless of which Timeline calls the action; for example, the absolute path to the instance california is _level0.westCoast.california. A relative path is different when called from different locations; for example, the relative path to california from sanfrancisco is _parent, but from portland, it's _parent._parent.california.

An absolute path starts with the name of the level into which the movie is loaded and continues through the display list until it reaches the target instance. You can also use the alias _root to refer to the topmost Timeline of the current level. For example, an action in the movie clip california that refers to the movie clip oregon could use the absolute path _root.westCoast.oregon.

The first movie to be opened in the Flash Player is loaded at level 0. You must assign each additional loaded movie a level number. When you use an absolute reference in ActionScript to reference a loaded movie, use the form _levelX, where X is the level number into which the movie is loaded. For example, the first movie opened in the Flash Player is called _level0; a movie loaded into level 3 is called _level3.

In the following example, two movies have been loaded into the player: TargetPaths.swf at level 0, and EastCoast.swf at level 5. The levels are indicated in the Debugger, with level 0 indicated as _root.

To communicate between movies on different levels, you must use the level name in the target path. For example, the portland instance would address the atlanta instance as follows:

_level5.georgia.atlanta

You can use the alias _root to refer to the main Timeline of the current level. For the main Timeline, the _root alias stands for _level0 when targeted by a clip also on _level0. For a movie loaded into _level5, _root is equal to _level5 when targeted by a movie clip also on level 5. For example, because southcarolina and florida are both loaded into the same level, an action called from the instance southcarolina could use the following absolute path to target the instance florida:

_root.eastCoast.florida

A relative path depends on the relationship between the controlling Timeline and the target Timeline. Relative paths can address targets only within their own level of the Flash Player. For example, you can't use a relative path in an action on _level0 that targets a Timeline on _level5.

In a relative path, use the keyword this to refer to the current Timeline in the current level; use the alias _parent to indicate the parent Timeline of the current Timeline. You can use the _parent alias repeatedly to go up one level in the movie clip hierarchy within the same level of the Flash Player. For example, _parent._parent controls a movie clip up two levels in the hierarchy. The topmost Timeline at any level in the Flash Player is the only Timeline with a _parent value that is undefined.

In the following example, each city (charleston, atlanta, and staugustine) is a child of a state instance, and each state (southcarolina, georgia, and florida) is a child of the eastCoast instance.

An action on the Timeline of the instance charleston could use the following target path to target the instance southcarolina:

_parent

To target the instance eastCoast from an action in charleston, you could use the following relative path:

_parent._parent

To target the instance atlanta from an action on the Timeline of charleston, you could use the following relative path:

_parent._parent.georgia.atlanta

Relative paths are useful for reusing scripts. For example, you could attach a script to a movie clip that magnifies its parent by 150%, as follows:

onClipEvent (load) {
	_parent._xscale = 150;
	_parent._yscale = 150;
}

You could then reuse this script by attaching it to any movie clip instance.

Whether you use an absolute or relative path, you identify a variable on a Timeline or a property of an object with a dot (.) followed by the name of the variable or property. For example, the following statement sets the variable name in the instance form to the value "Gilbert":

_root.form.name = "Gilbert";