Controlling External Timeline from Main Timeline

Controlling External Timeline from Main Timeline

Flash CS4 ActionScript 3.0 Tutorial

 

How to Control External Timeline with ActionScript in the Main Timeline

 

 

External movie timeline control can come from a ActionScript on the main timeline or a ActionScript in an external swf file. In this example we have ActionScript located on the main timeline that controls the playhead of the external timeline.

Tutorial Elements

The external .fla file and .swf file are placed in a folder named Swf. The external files should be named External.swf and External.fla. The Swf folder should be at the same level as the host swf file (Main.swf).

 

Step One

Open a new Flash document and name the default layer Actions.

Step Two

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

Step Three

Save your fla file in a Project folder. Name it Main.fla, and create a folder called Swf at the same level in the directory.

Step Four

Open a new flash document (File > New) named External.fla and save it in the Swf folder.

Step Five

In the External.fla file, click frame two and add a keyframe by pressing F6.

Step Six

Add some Static Text to frame two and frame one. For more info on creating text, see topic, Create Text. By scrubbing the timeline you should see the content in your two frames.

Step Seven

Add a new top layer called Actions.

Step Eight

Option double-click (PC - Alt double-click) frame one of the Actions layer in the External.fla file.

Step Nine

Copy/Paste the following code to the ActionScript panel.

stop();

Step Ten

Save your External.fla file and test your movie by pressing Cmd/Return (PC - Ctrl/Enter). It should open and stop at frame one.

Step Eleven

Return to your Main.fla file and Option double-click (PC - Alt double-click) frame one of the Actions layer.

Step Twelve

Copy/Paste the following code to the ActionScript panel.

var loadExt:Loader=new Loader;

loadExt.load(new URLRequest("Swf/External.swf"));

addChild(loadExt);

Step Thirteen

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

Step Fourteen

Copy/Paste the following code to the ActionScript panel.

stop();

var extTimeline:MovieClip=loadExt.content as MovieClip;

extTimeline.gotoAndStop(2);

Step Fifteen

Publish your movie by pressing Cmd/Return (PC - Ctrl/Enter). The external movie loads. Once the main timeline reaches frame 18, the external movie's timeline jumps to frame two.

Dissecting the Code

The code at Step Nine stops the External file at frame one.

The first two lines of the code at Step Twelve introduce a loader named loadExt and grab the External.swf file in the Swf folder. The addChild() line places the external file on the stage.

The code at Step Fourteen stops the main timeline at frame 18. It then introduces a new MovieClip variable named extTimeline.

The final line sends the External.swf timeline to frame two.

 

DAZ Studio FREE 3D MODELS AND SOFTWARE