User Guide

268 Chapter 10: Creating Custom Classes with ActionScript 2.0
return this.userName;
}
function set user(name:String):Void {
this.userName = name;
}
}
A getter method must not take any parameters. A setter method must take exactly one required
parameter. A setter method can have the same name as a getter method in the same scope. Getter/
setter methods cannot have the same name as other properties. For example, in the example code
above that defines getter and setter methods named
user, you could not also have a property
named
user in the same class.
Unlike ordinary methods, getter/setter methods are invoked without any parentheses or
arguments. For example, the following syntax could now be used to access or modify the value of
userName with the getter/setter methods previously defined:
var obj:LoginClass2 = new LoginClass2("RickyM");
// calling "get" method
trace(obj.user);
// calling "set" method
obj.user = "EnriqueI";
trace(obj.user);
Getter/setter method attributes cannot be used in interface method declarations.
Note: Implicit getter/setter methods are syntactic shorthand for the Object.addProperty()
method in ActionScript 1.
Understanding the classpath
In order to use a class or interface that youve defined, Flash must locate the external AS files that
contain the class or interface definition. The list of directories in which Flash searches for class
and interface definitions is called the classpath.
When you create an ActionScript class file, you need to save the file to one of the directories
specified in the classpath or a subdirectory therein. (You can modify the classpath to include the
desired directory path; see “Modifying the classpath” on page 270.) Otherwise, Flash wont be
able to resolve, or locate, the class or interface specified in the script. Subdirectories that you create
within a classpath directory are called packages and let you organize your classes. (For more
information, see “Using packages” on page 260.)
To learn about classpaths, see the following sections:
“Global and document-level classpaths” on page 268
“How the compiler resolves class references” on page 269
“Modifying the classpath” on page 270
Global and document-level classpaths
Flash has two classpath settings: a global classpath and a document-level classpath. The global
classpath applies to external AS files and to FLA files, and is set in the Preferences dialog box
(Edit > Preferences > ActionScript > ActionScript 2.0 Settings).