Control Nested Movie A with Button in Nested Movie B

Control Nested Movie A with Button in Nested Movie B

Flash CS4 ActionScript 3.0 Tutorial

 

How to Control a Nested Movie Timeline with a Button in Another Flash Nested Movie

 

 

Nested Movie Symbol timeline control can come from a button on the main stage or a button in another nested movie. In this example we have a button located inside a nested movie that controls the playhead of a second nested movie on main timeline. A Nested Symbol is one that is placed inside another Button Symbol or Movie Symbol.

Tutorial Elements

Movie Symbol with instance name buttonHolder_mc

Movie Symbol with instance name twoFrame_mc

Button Symbol with instance name nestedButton_btn (located inside buttonHolder_mc)

 

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 ButtonHolder, choose Movie Clip for type, then press OK.

Step Five

You are now inside the new Movie Symbol. Draw a rectangle on the stage. This will be your new button.

Step Six

Click the rectangle and press F8 to convert it to a Button Symbol. Name your button NestedButton and press OK.

Step Seven

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.

Step Eight

Click the ButtonHolder icon to return to the ButtonHolder edit screen.

Step Nine

Click the button and give it an instance name of nestedButton_btn in the Properties panel.

Step Ten

Click the Scene icon to return to the main timeline.

Step Eleven

Click frame one of the Content layer and drag the ButtonHolder from the Library to the stage.

Step Twelve

Click the new button and give it an instance name of buttonHolder_mc in the Properties panel.

Step Thirteen

Add an oval to the stage on the Content layer and press F8 to convert it to a Movie Symbol.

Step Fourteen

Double-click the oval. Now your are in the symbol edit mode. Press F6 to duplicate frame one

Step Fifteen

Change the color of the oval in frame two, the press the Scene icon to return to the main stage.

Step Sixteen

Click the oval Movie Symbol and assign it an instance name of twoFrame_mc in the Properties panel.

Step Seventeen

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

Step Eighteen

Copy/Paste the following code to the ActionScript panel.

twoFrame_mc.stop();

buttonHolder_mc.nestedButton_btn.addEventListener(MouseEvent.CLICK, frameChange);

function frameChange(e:MouseEvent):void{

twoFrame_mc.gotoAndStop(2);

}

Step Nineteen

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

Dissecting the Code

The first line stops the twoFrame_mc timeline at frame one. The next line adds an event listener to the nestedButton_btn that is inside the btnHolder_mc. Once it hears a mouse click, the function frameChange is run.

The line, twoFrame_mc.gotoAndStop(2), tells the twoFrame_mc timeline to go to frame 2 and stop.