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

About absolute and relative target paths

A target path is the address of the Timeline you want to target. The display list of Timelines in Flash is similar to the hierarchy of files and folders on a Web server.

The Movie Explorer shows the display list of movie clips in Authoring Mode.
 

Just as on a Web server, each Timeline in Flash can be addressed two ways: with an absolute path or a relative path. The absolute path of an instance is always the same, regardless of which Timeline calls the action; for example, the absolute path to the instance california is always _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.

Note: For more information about the Movie Explorer, see Flash Help.

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.

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. The target name for a level is _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.

The Debugger shows the absolute paths of all Timelines in the display list in Test-Movie Mode.
 

An instance always has the same absolute path, whether it's being called from an action in an instance on the same level, or from an action on a different level. For example, the instance bakersfield on level 0 always has the following absolute path in dot syntax:

_level0.california.bakersfield 

In slash syntax, the absolute path substitutes slashes for dots, as in the following:

_level0/california/bakersfield

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

In dot syntax, you can use the alias _root to refer to the main Timeline of the current level. For the main Timeline, or _level0, 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 1. For example, an action called from the instance southcarolina could use the following absolute path to target the instance florida:

_root.eastCoast.florida

In slash syntax, you can use / to refer to the main Timeline of the current level, as in the following:

/eastCoast/florida

In dot syntax in either Absolute or Relative Mode, you can use the same target path rules to identify a variable on a Timeline or a property of an object. For example, the following statement sets the variable name in the instance form to the value "Gilbert":

_root.form.name = "Gilbert";

In slash syntax in either Absolute or Relative Mode, you can identify a variable on a Timeline by preceding the variable name with a colon (:), as in the following:

/form:name = "Gilbert";

A relative path is dependent on the relationship between the controller Timeline and the target Timeline. You can use a relative path to reuse actions because the same action can target different Timelines depending on where the action is placed. Relative paths can address targets only within their own level of the Flash Player; they cannot address movies loaded into other levels. For example, you can't use a relative path in an action on _level0 that targets a Timeline on _level5.

In dot syntax, you can use the keyword this in a relative target path to refer to the current Timeline. You can use the alias _parent in a relative target path to indicate the parent Timeline of the current Timeline. The _parent alias can be used 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.

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.

The Movie Explorer shows the parent-child relationships of movie clips.
 

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

In slash syntax, you can use two dots (..) to go up a level in the hierarchy. To target eastCoast from an action in charleston, you could use the following path:

../..

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

_parent._parent.georgia.atlanta

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

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

You could then reuse this script by placing it on the Timeline of any movie clip.

For more information on addressing and dot syntax, see Chapter 2, "Writing Scripts with ActionScript".

For more information on Dot syntax and Slash syntax, see Using ActionScript's syntax.