It can be confusing to see that the movie clip script and the frame scripts inside the movie clip are at the same level. After all, you can only get at and edit the movie clip script while viewing the main timeline, and you can only get at and edit the movie clip’s frame scripts by viewing the movie clip’s timeline. Despite this, these scripts are all at the movie clip level. This is why the global variable clipToTell is available to both.
Now drag the “cog” movie clip to the work area a second time. Name this instance “cog2″. Place the following script on it:
onClipEvent (load) {
clipToTell = “cog3″;
}
This is all the second movie clip needs. It does not need a onClipEvent (enterFrame) handler because it does not advance one frame for every frame the main movie does. Instead, it gets its instruction to advance from “cog1″.
The second clip, however, has a value of “cog3″ for the clipToTell variable. That means that when it gets to frame 15, it tells “cog3″ to advance by one frame.
Create a third instance of the “cog” movie clip. Name this one “cog3″. No script is needed on this movie clip at all. There will be no “cog4″ in this example, so “cog3″ does not need to worry about telling another movie clip that it is time to advance.
This movie demonstrates more than just clip-to-clip communication. It also demonstrates how movie clip scripts and a movie clip’s frame scripts can share a global variable. This global is available only inside the movie clip and not to other sibling movie clips or the main timeline.
Taken From: Sams Teach Yourself Flashâ„¢ MX ActionScript in 24 Hours
Entries (RSS)