Using packages

You can organize your ActionScript class files in packages. A package is a folder that contains one or more class files, and which resides in a designated classpath folder. For more information about the classpath see Understanding the classpath. A package can, in turn, contain other packages, each with its own class files.

A common use of packages is to organize related classes. For example, you might have three different classes named Square, Circle, and Triangle that are defined in Square.as, Circle.as, and Trianagle.as, respectively. To make them easier to find and use, you put all of the class files in a folder named Shapes.

Referencing classes in packages

As discussed in Overview of creating and using classes, the name of the ActionScript class file must match the name of the class that it contains. For example, say you've created a class named Square, then you must save that AS file that contains that class definition as Square.as (to one of the designated classpath folders).

// In Square.as
class Square {
	// class body
}

Now, say you decide to create, the class name must be preceded by package path that contains the class file. Package folders are specified using dot-notation.

You can refer to any class defined in an ActionScript file in either of these directories without specifying a specific package. For example, if you have a class named Instructor defined in an Instructor.as file in the default directory, you can instantiate an Instructor object by issuing the following statement:

englishInstructor = new Instructor();

However, if you want to refer to classes that are not stored in the default directory, you must tell Flash where the package file is located, as described in the following sections.