11.11. Controlling Movie Clip Playback from Different Timelines

Problem

You want to use ActionScript within one movie clip’s timeline in order to control another movie clip.

Solution

Use a relative target path.

Discussion

You can control one movie clip from another movie clip’s timeline by using the correct target path. A target path is the address by which Flash can locate a movie clip instance (or button or text field instance), and target paths come in two varieties: relative and absolute.

An absolute target path is a way for Flash to locate an instance from the top down. All absolute target paths begin with _root or _level0 (or _level1, _level2, and so on), which is the topmost structure in a Flash movie. For example, if a movie clip instance named mClip exists on the main timeline, you could reference it with the absolute target path of _root.mClip. Flash then begins looking first at _root, and then locates a movie clip instance named mClip within _root. If there is a movie clip instance named mNested nested within mClip, then an absolute target path would be _root.mClip.mNested.

Absolute addresses may seem like a good way to target instances. However, there are some drawbacks. One of the major drawbacks is that in many, if not most, cases, your code will stop working if and when you load the .swf file into another .swf file. Flash Player 7 and higher versions support a _lockroot property that enables you to correct that. However, if you are publishing to previous versions of Flash, ...

Get Flash 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.