Go to a Specific Frame on Main Timeline

Go to a Specific Frame on Main Timeline

Flash CS4 ActionScript 3.0 Tutorial


How to Control the Main Timeline with a Button on the Main Flash Stage



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 on the main stage that controls the playhead of the main timeline.

Tutorial Elements

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

Click frame one of the Content layer and draw an oval shape with the Oval tool.

Step Four

Click the oval and press F8 to convert it to a Button Symbol.

Step Five

Name the button, MainButton and choose Button for type.

Step Six

Double-click the oval object to open the edit mode. Press F6 three times to copy/paste the Up content to the Over, Down and Hit keyframes.

Step Seven

Click the Scene icon to return to the main timeline.

Step Eight

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

Step Nine

Click frame two of the Content layer and add a blank keyframe by pressing F7.

Step Ten

Using the Text tool, add the following Static text (Frame Two) to frame two of the Content layer.

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, frameChange);

function frameChange(e:MouseEvent):void{



Step Thirteen

Test your movie by pressing Cmd/Return (PC - Ctrl/Enter). Click the 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 mainButton_btn. Once it hears a mouse click, the function frameChange is run.

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


Contribute Ad