Web Server

przez | 20/01/2009

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.
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.

To retrieve a copy of a movie clip or sound from the library and play it as part of your movie, you use the attachMovie method of the MovieClip object or the attachSound method of the Sound object. The attachMovie method loads a movie clip as a child of the clip that loads it and plays it as the movie runs. The attachSound method attaches a sound to an instance of the Sound object.

To use ActionScript to attach a movie clip or sound from the library, you must assign a unique linkage identifier to the movie clip or sound. You can assign this name in the Linkage Properties dialog box.

When a movie plays, Flash loads all movie clips and sounds that are added with attachMovie or attachSound before the first frame of the movie. This can create a delay before the first frame plays. When you assign a linkage identifier to an element, you can also specify whether this content should be added before the first frame. If it isn’t added in the first frame, you must include an instance of it in some other frame of the movie; if you don’t, the element will not be exported to the SWF file.

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 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.