EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Example: Writing Custom Classes

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Example: Writing custom classes 263
Example: Writing custom classes
Now that youve 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 cant
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 classs 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
CAUTION
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.

Table of Contents

Related product manuals