Using Packages; Importing Classes - MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual

Actionscript reference guide
Hide thumbs Also See for FLASH MX 2004 - ACTIONSCRIPT:
Table of Contents

Advertisement

Using packages

You can organize your ActionScript class files in packages. A package is a directory that contains
one or more class files, and that resides in a designated classpath directory. (See
the classpath" on page
each with its own class files.
Package names must be identifiers; that is the first character must be a letter, underscore (
dollar sign (
), and each subsequent character must be a letter, number, underscore, or dollar sign.
$
Packages are commonly used to organize related classes. For example, you might have three
related classes, Square, Circle, and Triangle, that are defined in Square.as, Circle.as, and
Triangle.as. Assume that you've saved the AS files to a directory specified in the classpath.
// In Square.as:
class Square {}
// In Circle.as:
class Circle {}
// In Triangle.as:
class Triangle {}
Because these three class files are related, you might decide to put them in a package (directory)
called Shapes. In this case, the fully qualified class name would contain the package path, as well
as the simple class name. Package paths are denoted with dot syntax, where each dot indicates
a subdirectory.
For example, if you placed each AS file that defines a shape in the Shapes directory, you would
need to change the name of each class file to reflect the new location, as follows:
// In Shapes/Square.as:
class Shapes.Square {}
// In Shapes/Circle.as:
class Shapes.Circle {}
// In Shapes/Triangle.as:
class Shapes.Triangle {}
To reference a class that resides in a package directory, you can either specify its fully qualified
class name or import the package by using the

Importing classes

To reference a class in another script, you must prefix the class name with the class's package path.
The combination of a class's name and its package path is the class's fully qualified class name. If a
class resides in a top-level classpath directory—not in a subdirectory in the classpath directory—
then its fully qualified class name is just its class name.
To specify package paths, use dot notation to separate package directory names. Package paths are
hierarchical, where each dot represents a nested directory. For example, suppose you create a class
named Data that resides in a com/network/ package in your classpath. To create an instance of
that class, you could specify the fully qualified class name, as follows:
var dataInstance = new com.network.Data();
169.) A package can, in turn, contain other packages, called subpackages,
statement (see below).
import
"Understanding
), or
_
Importing classes
171

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Table of Contents