228
Classes
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 {}
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...