Control Main Timeline with Button in Nested Movie
Flash CS4 ActionScript 3.0 Tutorial
How to Control the Main Timeline with a Button in a Nested 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 a nested movie that controls the playhead of the main timeline. A Nested Symbol is one that is placed inside another Button Symbol or Movie Symbol.
Movie Symbol with instance name buttonHolder_mc
Button Symbol with instance name nestedButton_btn (located inside buttonHolder_mc)
Open a new Flash document and name the default layer Content.
Add a new top layer and name it Actions.
Choose Insert > New Symbol (Cmd/F8 (PC - Ctrl/F8).
Name your symbol ButtonHolder, choose Movie Clip for type, then press OK.
You are now inside the new Movie Symbol. Draw a rectangle on the stage. This will be your new button.
Click the rectangle and press F8 to convert it to a Button Symbol. Name your button NestedButton and press OK.
Double-click the button to edit the button. Press F6 three times to copy/paste the Up content to the Over, Down and Hit keyframes.
Click the ButtonHolder icon to return to the ButtonHolder edit screen.
Click the button and give it an instance name of nestedButton_btn in the Properties panel.
Click the Scene icon to return to the main timeline.
Click frame one of the Content layer and drag the ButtonHolder from the Library to the stage.
Click the new button and give it an instance name of buttonHolder_mc in the Properties panel.
Option double-click (PC - Alt double-click) frame one of the Actions layer.
Copy/Paste the following code to the ActionScript panel.
Click frame two of the Content layer and add a blank keyframe by pressing F7.
Using the Text tool, add the following Static text to frame two of the Content layer.
Test your movie by pressing Cmd/Return (PC - Ctrl/Enter). Click the nested button. The main timeline should go to frame two and stop.
Dissecting the Code
The first line stops the timeline at frame one. The next line adds an event listener to the nestedButton_btn that is inside the buttonHolder_mc. Once it hears a mouse click, the function frameChange is run.
The line, this.gotoAndStop(2), tells the main timeline to go to frame 2 and stop.