Example: Writing custom classes
263
Example: Writing custom classes
Now that you’ve explored the basics of a class file, and what kinds of things it contains, it’s
time to learn some of the general guidelines for creating a class file. The first example in this
chapter shows you how to write classes and package them. The second example shows you
how to use those class files with a FLA file.
As discussed in
“Writing custom class files” on page 235
, a class consists of two main parts:
the
declaration
and the
body
. The class declaration consists minimally of the class statement,
followed by an identifier for the class name, and then left and right curly braces (
{}
).
Everything inside the braces is the class body, as shown in the following example:
class className {
// class body
}
Remember: you can define classes only in external ActionScript files. For example, you can’t
define a class in a frame script in a FLA file. Therefore, you create a new file for this example.
In its most basic form, a class declaration consists of the
class
keyword, followed by the class
name (Person, in this case), and then left and right curly braces (
{}
). Everything between the
braces is called the class body and is where the class’s properties and methods are defined.
By the end of this example, the basic ordering of your class files is as follows:
■
Documentation comments
■
Class declaration
■
Constructor function
■
Class body
You do not write subclasses in this chapter. For more information on inheritance and
subclassing, see
Chapter 8, “Inheritance,” on page 301
.
This example includes the following topics:
■
“About general guidelines for creating a class” on page 264
■
“Creating and packaging your class files” on page 266
■
“Writing the constructor function” on page 268
■
“Adding methods and properties” on page 270
■
“Controlling member access in your classes” on page 273
■
“Documenting the classes” on page 274
CAU
T
ION
ActionScript code in external files is compiled into a SWF file when you publish, export,
test, or debug a FLA file. Therefore, if you make any changes to an external file, you must
save the file and recompile any FLA files that use it.
Содержание 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...