ActionScript (Internal)

ActionScript (Internal)

Flash CS4 ActionScript 3.0 Tutorial


How to Create an Actions layer for Your ActionScript Code in Flash


There are two common ways to add ActionScript to your Flash document. The easiest method is to add your code directly to the timeline.

A second method involves writing your code in a separate .as file that is in the same directory as your .fla file. When you compile your .swf file, the external code in the .as file is included in the .swf file. This is an example of adding a rectangle to the stage as a Sprite with all the code in a keyframe on the main timeline.


Step One

Open a new Flash document and rename the default layer Actions.

Step Two

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

Step Three

Copy/Paste the following code to the ActionScript panel.

var greenBox_mc:Sprite=new Sprite;






Step Four

Publish your movie by pressing Cmd/Return (PC - Ctrl/Enter). The green box with the rounded corners appears on the stage.

Dissecting the Code

The first line of the code at Step Three establishes a new variable named greenBox_mc that is part of the Sprite class. Sprites are single frame MovieClips.

We then fill the box with green, stroke it with a two point gray stroke and set it's parameters to define it as a rounded rectangle.

The final step is to add the rectangle to the stage with the addChild() code.


Stock Photos from 123RF