Control Nested Movie with Button on Main Timeline

Control Nested Movie with Button on Main Timeline

Flash CS4 ActionScript 3.0 Tutorial


How to Control a Nested Movie with a Button on the Main Timeline



Nested Movie Symbol timeline control can come from a button on the main stage or from a button in another nested movie. In this example we have a button located on the main timeline that tells the nested movie to go to frame two and stop. A Nested Symbol is one that is placed inside another Button Symbol or Movie Symbol.

Tutorial Elements

Movie Symbol with instance name nestedMovie_mc

Button Symbol with instance name mainButton_btn


Step One

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

Step Two

Add a new top layer and name it Actions.

Step Three

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

Step Four

Name your symbol NestedMovie, choose Movie Clip for type, then press OK.

Step Five

You are now inside the new Movie Symbol. Draw a rectangle on the stage.

Step Six

Press F6 and a duplicate of frame one is added at frame two. Change the color of the rectangle at frame two.

Step Seven

Click the Scene icon to return to the main stage.

Step Eight

Add a Button Symbol to the main stage on the Content layer and give it an instance name of mainButton_btn. For more information, see topic Symbols.

Step Nine

Drag an instance of the NestedMovie symbol from the Library to the stage Content layer.

Step Ten

Give the NestedMovie an instance name of nestedMovie_mc in the Properties panel.

Step Eleven

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

Step Twelve

Copy/Paste the following code to the ActionScript panel.


mainButton_btn.addEventListener(MouseEvent.CLICK, onBtnPress);

function onBtnPress(e:MouseEvent):void {



Step Thirteen

Test your movie by pressing Cmd/Return (PC - Ctrl/Enter). Click the button on the main timeline. The nested movie should go to frame two and stop.

Dissecting the Code

The first line stops the nested movie's timeline at frame one. The next line adds an event listener to the mainButton_btn. Once it hears a mouse click, the function onBtnPress is run.

The line, nestedMovie_mc.gotoAndStop(2), tells the nested movie timeline to go to frame 2 and stop. career skills