268
Classes
2.
Create the required directory structure after you’ve chosen a package name.
For example, if your package was named
com.macromedia.utils
, you would need to
create a directory structure of com/macromedia/utils and place your classes in the
utils folder.
3.
Use the com.macromedia.utils prefix for any class you create in this package.
For example, if your class name was ClassA, the full class name would need to be
com.macromedia.utils.ClassA
within the
com/macromedia/utils/ClassA.as
class file.
4.
If you change your package structure at a future point, remember to modify not only the
directory structure, but the package name within each class file, as well as every import
statement or reference to a class within that package.
To continue writing the class files, see
“Writing the constructor function” on page 268
.
Writing the constructor function
You have already learned how to write the class declaration in
“Creating and packaging your
class files” on page 266
. In this part of the chapter, you write what’s called the class file’s
constructor function
.
Constructors are functions that you use to initialize (
define
) the properties and methods of a
class. By definition, constructors are functions within a class definition that have the same
name as the class. For example, the following code defines a Person class and implements a
constructor function. In OOP, the constructor function initializes each new instance of
a class.
A class’s constructor is a special function that is called automatically when you create an
instance of a class using the
new
operator. The constructor function has the same name as the
class that contains it. For example, the Person class you created contained the following
constructor function:
// Person class constructor function
public function Person (uname:String, age:Number) {
this.__name = uname;
this.__age = age;
}
NO
TE
You learn how to write the comments, statements, and declarations in later sections.
Содержание 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...