26 July 2010

An ActionScript 3 class (AS file) is written as a text document, separate from an Adobe Flash Professional FLA file or Flex MXML file that may use it. The class file must have the same name as the class, and is saved with an .as extension. The class file should be contained in a hierarchy of folders matching the package structure of your class.

For example, if you are creating the Scorekeeper class, you'll save a file named The complete class name including package is The Scorekeeper class is contained in the "" package, so the file must be saved in a folder structure like this: /com/example/game/. The com folder can be contained in the root folder of your application, or in a folder that's part of the ActionScript classpath for your application.

You can create classes in an ActionScript-specific program such as Flash Builder or Flash Professional, in a general programming tool such as Dreamweaver, or in any text-editing program that allows you to work with plain text documents.

You use the class statement to define the name of a class. A class must be specified as "public" in order for other code to create instances of that class (essentially, except in a few special circumstances, all ActionScript 3 classes must be public).

The class statement, in turn, must be enclosed in a package statement, indicating the name of the package in which your class is found. The syntax is similar to the class statement syntax: the word package followed by the package name, then a pair of curly braces surrounding the package contents (the single class statement plus any import statements that are necessary):

To add the class and package statements to the Scorekeeper class, enter the following code:

package { public class Scorekeeper { // class contents (methods and properties) go here } }

To learn more about creating classes, see the section titled Class property attributes in Learning ActionScript 3.0.

Tool used

Related concepts