When you use a class, you can also extend existing classes and add new functionality or
modify existing functionality. For example, if you create three very similar classes, you can
write a base class and then write two other classes that extend the base class. These two classes
can add additional methods and properties, so that you don't need to create three class files
that all duplicate the same code and logic.
Another benefit of using classes is code reusability. For example, if you create a custom class
that creates a custom progress bar using the Drawing application programming interface
(API), you could save the progress bar class in your classpath and reuse the same code in all of
your Flash documents by importing the custom class. For more information on setting the
classpath, see
"About importing class files" on page 239
and
"About setting and modifying
the classpath" on page
240.
About packages
When you are creating classes, you 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
"About importing class files" on page 239
and
"About setting and
modifying the classpath" on page
240). A package can, in turn, contain other packages, called
subpackages, each with its own class files.
Like variables, package names must be identifiers; that is, the first character can be a letter,
underscore (
), or dollar sign (
), and each subsequent character can be a letter, number,
_
$
underscore, or dollar sign. There are preferred ways to name packages, which for example
recommend that you avoid using underscores or dollar sign characters. For more information
on naming packages, see
"Naming packages" on page
741.
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 ActionScript files to a directory specified in the
classpath, as shown in the following example:
// In Square.as:
class Square {}
// In Circle.as:
class Circle {}
// In Triangle.as:
class Triangle {}
228
Classes
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?