Controlling Nested Timeline from Main Timeline

Controlling Nested Timeline from Main Timeline

Flash CS4 ActionScript 3.0 Tutorial

 

How to Control a Nested Timeline with Code on the Main Flash 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 a nested movie at any level of the hierarchy.

In this example we will nest one Movie Symbol within another Movie Symbol. ActionScript is then added to the main timeline to control the nested Movie Symbol.

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.

Step Eight

Double-Click the RedBox symbol to enter the editing mode.

Step Nine

Add a new layer inside RedBox and name it Actions.

Step Ten

Add keyframes for both layers at frame five by clicking frame five and pressing F6.

Step Eleven

Add the following code to the Actions layer keyframes one and five.

stop();

Step Twelve

Change the color of the rectangle to blue at frame five.

Step Thirteen

Return to the main stage by clicking the scene icon.

Step Fourteen

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

Step Fifteen

Select the instance of the Holder symbol and assign it an instance name of holder_mc in the Properties panel.

Step Sixteen

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

Step Seventeen

Copy/Paste the following code to the ActionScript panel.

holder_mc.nested_mc.play();

Step Eighteen

Click frame twenty of the Content layer and press F5 to extend the content for twenty frames.

Step Nineteen

Publish your movie by pressing Cmd/Return (PC - Ctrl/Enter). The movie on the main stage plays. When the main timeline hits frame 20, it loops back to frame one. Each time the timeline hits frame one, the external movie is told to play, which changes the color.

Dissecting the Code

The stop code added at Step Eleven stops the timeline whenever it hits frame one or frame five.

The code at Step Seventeen tells the timeline of the nested_mc (inside the holder_mc) to play.