Controlling Main Timeline from Nested Movie

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.

Tutorial Elements

Movie Symbol named holder_mc

Movie Symbol named nested_mc


Step One

Open a new Flash document and add one additional layer.

Step Two

Name the top layer Actions and the lower layer Content.

Step Three

Choose Insert > New Symbol (Cmd/F8 (PC - Ctrl/F8).

Step Four

Select Movie Clip for type and name your new symbol Holder.

Step Five

Use the Rectangle tool to add a red rectangle inside the Holder Movie Symbol at the center of the stage.

Step Six

Select the rectangle and press F8 to convert it to a Movie Symbol. Name the symbol RedBox.

Step Seven

Click the rectangle and assign it an instance name of nested_mc in the Properties panel.

Step Eight

Double-Click RedBox to enter the symbol editing mode.

Step Nine

Add a new layer inside RedBox and name it Actions.

Step Ten

Add 18 frames of animation to the rectangle.

Step Eleven

Select frame 18 of the Actions layer and press F6 to add a keyframe.

Step Twelve

Option double-click (PC - Alt double-click) frame 18 of the Actions layer.

Step Thirteen

Add the following code to the Actions layer keyframe at frame 18.



Step Fourteen

Return to the main stage by clicking the scene icon.

Step Fifteen

Drag the Holder symbol from the Library to the center of the stage on the Content layer.

Step Sixteen

Add a keyframe to the Actions layer by selecting frame two and pressing F6.

Step Seventeen

Option double-click (PC - Alt double-click) frame two of the Actions layer.

Step Eighteen

Copy/Paste the following code to the ActionScript panel.


Step Nineteen

Repeat steps seventeen and eighteen for frame one of the Actions layer.

Step Twenty

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.