Controlling Main Timeline from Nested Movie
Flash CS4 ActionScript 3.0 Tutorial
How to Control Main Timeline with Code in Nested Movies's Timeline
Nesting symbols is a common technique when working with Button Symbols and Movie Symbols. It allows you to create a parent/child relationship for simplified moving. You can also use ActionScript to talk to and from a nested movie.
A nested movie is a Movie Symbol that resides inside another Movie Symbol.
In this example we will nest one Movie Symbol within another Movie Symbol. ActionScript is then added to the nested movie timeline to control the main timeline.
Movie Symbol named holder_mc
Movie Symbol named nested_mc
Open a new Flash document and add one additional layer.
Name the top layer Actions and the lower layer Content.
Choose Insert > New Symbol (Cmd/F8 (PC - Ctrl/F8).
Select Movie Clip for type and name your new symbol Holder.
Use the Rectangle tool to add a red rectangle inside the Holder Movie Symbol at the center of the stage.
Select the rectangle and press F8 to convert it to a Movie Symbol. Name the symbol RedBox.
Click the rectangle and assign it an instance name of nested_mc in the Properties panel.
Double-Click RedBox to enter the symbol editing mode.
Add a new layer inside RedBox and name it Actions.
Add 18 frames of animation to the rectangle.
Select frame 18 of the Actions layer and press F6 to add a keyframe.
Option double-click (PC - Alt double-click) frame 18 of the Actions layer.
Add the following code to the Actions layer keyframe at frame 18.
Return to the main stage by clicking the scene icon.
Drag the Holder symbol from the Library to the center of the stage on the Content layer.
Add a keyframe to the Actions layer by selecting frame two and pressing F6.
Option double-click (PC - Alt double-click) frame two of the Actions layer.
Copy/Paste the following code to the ActionScript panel.
Repeat steps seventeen and eighteen for frame one of the Actions layer.
Publish your movie by pressing Cmd/Return (PC - Ctrl/Enter). The movie on the main stage stops at frame one where it plays the nested movie. Once the nested movie reaches the end, the main timeline advances to frame two and the stage is empty.
Dissecting the Code
The stop code added at Step Twelve stops the timeline of the nested movie at frame 18. The next line tells the current movie's parent's parent (the main timeline) to play.
The code at Step Seventeen tells the main timeline to stop (so the nested movie can play). Once it is told to play again, it is told to stop again at frame two.