Flash ActionScript

Embedded in Flash is a rich programming language called ActionScript. With only a handful of commands, you can create interactive animations. Commands are typed (or dragged) into the Actions window available under Window > Actions. There are two places we can attach our commands: on the Timeline within a frame, and attached to a Button.

Timeline

It is highly suggested that any commands for the Timeline be placed in a layer by themselves. While it is technically possible to mix images and commands on the same layer, it becomes confusing.

To apply a command, first select the frame and layer, then type or drag the command into the Actions window.

stop();
Normally, Flash plays one frame after the next in sequential order. This command quite literally stops the playback on the present frame. Probably there is a button on the frame that will allow the playback to jump elsewhere in your movie.

gotoAndPlay(NNN);
After playing the current frame, Flash jumps to frame number NNN and continues playing the animation.

gotoAndPlay("framelabel");
After playing the current frame, Flash jumps to the frame with name framelabel and continues playing the animation. (Frame labels are set in the timeline. Click on a keyframe, and then choose Window > Properties. Then, type a name in the box.)

gotoAndStop(NNN);
After playing the current frame, Flash jumps to frame number NNN and stops the playback, awaiting the press of a button.

gotoAndStop("framelabel");
After playing the current frame, Flash jumps to the frame with name framelabel and stops the playback, awaiting the press of a button.

Button

To apply a command to a button, first select the button, then select Window > Properties. Type a name in the Instance Name box to name the button. Traditionally, button names have the extension “_btn”.

Then, in an ActionScript window, type the following. In this example, the button is named “blue_btn”:

function BlueplayMovie(event:MouseEvent):void
{
gotoAndPlay("mighty");
}

blue_btn.addEventListener(MouseEvent.CLICK, BlueplayMovie);

When the button is clicked, Flash jumps to the frame named “mighty” and continues playing the animation. (Note that you have added an Event Listener that sits and waits for the button to be pressed. When it is pressed, the Listener invokes a function—in this example, called “BluePlayMovie”. That function in turn does the actual jump to the label called “mighty”. It is also possible to replace the gotoAndPlay within the function with a gotoAndStop.)