Control Main Timeline from External swf
Flash CS4 ActionScript 3.0 Tutorial
How to Control the Main Timeline from an External Flash Movie
Main timeline control can come from a button on the main stage, a button in a nested movie or a button in an external swf file. In this example we have a button located inside an external movie that controls the playhead of the main timeline. The external file is introduced to the main timeline with the Loader class.
External .fla file and .swf file in folder named Swf. The external files should be named external.swf and external.fla. Swf folder should be at the same level as the host swf file.
Open a new Flash document and name the default layer Content.
Add a new top layer and name it Actions.
Click frame two of the Content layer and press F6 to add a keyframe.
Using the Text tool add some text to the Content layer, frame 2.
Save and name your fla file, Main.fla. Create a folder named Swf at the same level in the directory.
Open a new flash document named External.fla and save it in the Swf folder (File > New)
Add a new layer to the External file named Actions.
Option double-click (PC - Alt double-click) frame one of the Actions layer in the External file.
Copy/Paste the following code to the ActionScript panel.
Save your file and publish your movie by pressing Cmd/Return (PC - Ctrl/Enter) then close the External.fla file. Don't worry if you see an error if you click the button at this step. It goes away once the file is opened from the Main file.
Returning to the original Main.fla file, add a keyframe to the Actions layer at frame two by pressing F6. This layer should have two keyframes, one at frame one and one at frame two.
Option double-click (PC - Alt double-click) frame one of the Actions layer.
Copy/Paste the following code in the ActionScript panel at frame one of the Actions layer.
var loadExt:Loader=new Loader;
Option double-click (PC - Alt double-click) frame two of the Actions layer.
Copy/Paste the following code in the ActionScript panel at frame two of the Actions layer.
Test your movie by pressing Cmd/Return (PC - Ctrl/Enter). The swf file with the external button appears. Click the button and you are sent to frame two of the main timeline.
Dissecting the Code
The first line of the code at Step Ten adds an event listener to the external_btn that is inside the External.swf file. Once it hears a mouse click, the function onReturn is run. The onReturn function says, "go to the the main timeline and stop at frame two".
The code at Step Fourteen stops the main timeline at frame one. A new variable of the loader class named loadExt is introduced. The loadExt variable is loaded with the External.swf file. Once it is loaded, it is added to the stage at the bottom level.
The Step Sixteen code removes the external swf file. Since we added the file to the bottom of the stack with the addChildAt(loadExt,0) command, it is easy to remove the content from the lowest level by saying removeChildAt(0). For more information about adding and removing children see topic, Display List.