When I was deciding what topics I wanted to write about for my blog I had a hard time determining the difficulty of the tutorials. As a result I thought I would do an intro to ActionScript 3 tutorial before diving into more advanced code.
In this tutorial we will use look at the basic structure of an AS3 document, how it connects to Flash and how it gets compiled. You will need a copy of Flash CS3 or Flash CS4; if you don’t have this you can get a 30 day trial version from Adobe.
Open Flash and create two new files ([FILE]/[NEW]): “Flash File (ActionScript 3.0)” and “ActionScript File”. Save them as:
- hellowolrd.fla
- HelloWorld.as
The ActionScript(.as) file name is case sensitive.
Basic AS Code:
package {
import flash.display.Sprite;
public class HelloWorld extends Sprite{
public function HelloWorld ():void{
trace(“Hello World!”);
}
}
}
All of your code will be contained within a “package”. You can name packages and have multiple packages but we aren’t going to cover that here.
Next you import existing classes (that Adobe has created) that are going to be used in the program. On line 2 we are importing the “Sprite” class, which is similar to the MovieClip object but doesn’t have a timeline. Basically, it gives us a foundation to put objects on.
Next we have the Class “HelloWorld”. Notice the capitalizations, the class name must match the file name exactly. We extend the Sprite class to it so that our HelloWorld application can display objects.
Next we have our public function HelloWorld, referred to as the Constructor Method. This function is named identical to the class name, it will run automatically when the program is run.
Finally we have a simple trace statement, which when the program is rendered it will output the phrase “Hello World!”.
Connecting the FLA and AS files
We now need to tell the FLA file what source code to use. In “helloWorld.fla” open the “Properties” panel; if you can’t find it, you can go to [Window]/[Properties]. Under “Publish” there is a input box called “Class”, type “HelloWorld” into this box. This capitalization must match the name of the file and you can leave of the extension.

Click on the edit icon to the right of the box:
. If your code was correct, and both files were saved in the correct spot it should open up your ActionScript file.
Compiling/rendering
Go to [FILE]/[PUBLISH]; you can also hit [Ctrl]+[Enter] on your keyboard.
When flash compiles a program it takes you FLA file, your ActionScript file and any classes you imported (in this case we imported the Sprite class) and combines then into one SWF file that can be placed on a web page.
Woot Woot
Exciting right? Yeah I didn’t think so, but this code will serve as the starting point for future tutorials.
Tags: actionscript 3, beginner, Flash, tutorial










[...] you are new to Actionscript 3, take a look at this tutorial first to get the basics. You will need to download this commercial to do this [...]