User Guide

26 Getting Started with ActionScript
ActionScript class definition: a definition of an ActionScript class, including its method
and property definitions.
When you define a class, you can access the ActionScript code in the class by creating an
instance of the class and using its properties, methods, and events, just as you would with
any of the built-in ActionScript classes. This requires two parts:
Use the import statement to specify the full name of the class, so the ActionScript
compiler knows where to find it. For example, if you want to use the MovieClip class
in ActionScript, you first need to import that class using its full name, including
package and class:
import flash.display.MovieClip;
Alternatively, you can import the package that contains the MovieClip class, which is
equivalent to writing separate import statements for each class in the package:
import flash.display.*;
The only exceptions to the rule that a class must be imported in order to refer to that
class in your code are the top-level classes which are not defined in a package.
Write code which specifically refers to the class name (usually declaring a variable with
that class as its data type, and creating an instance of the class to store in the variable).
By referring to another class name in ActionScript code, you tell the compiler to load
the definition of that class. For example, given an external class called Box, this
statement causes a new instance of the Box class to be created:
var smallBox:Box = new Box(10,20);
When the compiler comes across the reference to the Box class for the first time, it
searches the loaded source code to locate the Box class definition.
Example: Creating a basic application
You can create external ActionScript source files with an .as extension using Flash, Flex
Builder, Dreamweaver, or any text editor.
ActionScript 3.0 can be used within a number of application development environments,
including the Flash authoring and Flex Builder tools.
This section walks through the steps in creating and enhancing a simple ActionScript 3.0
application using the Flash authoring tool or the Flex Builder 2 tool. The application you’ll
build presents a simple pattern for using external ActionScript 3.0 class files in Flash and Flex
applications. That pattern will apply to all of the other example applications in this book.