52
Chapter 2: Creating Custom Classes with ActionScript 2.0
If you are creating multiple custom classes, use
packages
to organize your class files. A package is a
directory that contains one or more class files and resides in a designated classpath directory. Class
names must be fully qualified within the file in which it is declared—that is, it must reflect the
directory (package) in which it is stored.
For example, a class named myClasses.education.curriculum.RequiredClass is stored in the
myClasses/education/curriculum package. The class declaration in the RequiredClass.as file looks
like this:
class myClasses.education.curriculum.RequiredClass {
}
For this reason, it’s good practice to plan your package structure before you begin creating classes.
Otherwise, if you decide to move class files after you create them, you will have to modify the
class declaration statements to reflect their new location. For more information on organizing
classes, see
“Using packages” on page 57
.
For more information on creating and using classes, see the following topics:
•
“Constructor functions” on page 52
•
“Creating properties and methods” on page 53
•
“Controlling member access” on page 53
•
“Initializing properties inline” on page 54
•
“Creating subclasses” on page 55
Constructor functions
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
function Person (myName:String, myAge:Number) {
this.name = myName;
this.age = myAge;
}
If no constructor function is explicitly declared—that is, if you don’t create a function whose
name matches that of the class—the compiler automatically creates an empty constructor
function for you.
A class can contain only one constructor function; overloaded constructor functions are not
allowed in ActionScript 2.0.
A constructor function should have no return type.
The
this
keyword is not required in ActionScript 2.0 class definitions because the compiler
resolves the reference and adds it into the bytecode. However, using
this
can improve your code’s
readability..
Содержание FLEX
Страница 1: ...Flex ActionScript Language Reference ...
Страница 8: ......
Страница 66: ...66 Chapter 2 Creating Custom Classes with ActionScript 2 0 ...
Страница 76: ......
Страница 133: ...break 133 See also for for in do while while switch case continue throw try catch finally ...
Страница 135: ...case 135 See also break default strict equality switch ...
Страница 146: ...146 Chapter 5 ActionScript Core Language Elements See also break continue while ...
Страница 229: ...while 229 i 3 The following result is written to the log file 0 3 6 9 12 15 18 See also do while continue for for in ...
Страница 808: ...808 Chapter 7 ActionScript for Flash ...
Страница 810: ...810 Appendix A Deprecated Flash 4 operators ...
Страница 815: ...Other keys 815 Num Lock 144 186 187 _ 189 191 192 219 220 221 222 Key Key code ...
Страница 816: ...816 Appendix B Keyboard Keys and Key Code Values ...
Страница 822: ...822 Index ...