Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 40

Programming actionscript 3.0
Table of Contents

Advertisement

Most of the Flash Player API is organized under the flash package. For example, the
flash.display package contains the display list API, and the flash.events package contains the
new event model. A detailed discussion of the Flash Player API packages can be found in Part
3 of this book. For more information, see
"Flash Player APIs" on page
335.
Creating packages
ActionScript 3.0 provides significant flexibility in the way you organize your packages, classes,
and source files. Previous versions of ActionScript allowed only one class per source file and
required that the name of the source file match the name of the class. ActionScript 3.0 allows
you to include multiple classes in one source file, but only one class in each file can be made
available to code that is external to that file. In other words, only one class in each file can be
declared inside a package declaration. You must declare any additional classes outside your
package definition, which makes those classes invisible to code outside that source file. The
name of the class declared inside the package definition must match the name of the source file.
ActionScript 3.0 also provides more flexibility in the way you declare packages. In previous
versions of ActionScript, packages merely represented directories in which you placed source
files, and you didn't declare packages with the
statement, but rather included the
package
package name as part of the fully qualified class name in your class declaration. Although
packages still represent directories in ActionScript 3.0, packages can contain more than just
classes. In ActionScript 3.0, you use the
statement to declare a package, which means
package
that you can also declare variables, functions, and namespaces at the top level of a package.
You can even include executable statements at the top level of a package. If you do declare
variables, functions, or namespaces at the top level of a package, the only attributes available
at that level are
and
, and only one package-level declaration per file can use
public
internal
the
attribute, whether that declaration is a class, variable, function, or namespace.
public
Packages are useful for organizing your code and for preventing name conflicts. You should
not confuse the concept of packages with the unrelated concept of class inheritance. Two
classes that reside in the same package will have a namespace in common, but are not
necessarily related to each other in any other way. Likewise, a nested package may have no
semantic relationship to its parent package.
40
ActionScript Language and Syntax

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents