64
Chapter 2: Creating Custom Classes with ActionScript 2.0
However, if you want to use a more concise syntax, use
implicit
getter/setter methods. Implicit
getter/setter methods let you access class properties in a direct manner, while maintaining good
OOP practice.
To define these methods, use the
get
and
set
method attributes. You create methods that get or
set the value of a property, and add the keyword
get
or
set
before the method name, as shown in
the following example:
class LoginClass2 {
private var userName:String;
function LoginClass2(name:String) {
this.userName = name;
}
function get user():String {
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.
Understanding the classpath
In order to use a class or interface that you’ve defined, Flash must locate the external AS files that
contain the class or interface definition. The list of directories in which Flex searches for class and
interface definitions is called the
ActionScript classpath
.
By default, the
flex_root
/WEB-INF/flex/user_classes directory is part of the ActionScript
classpath. In addition, ActionScript classes can be in the same directory as the MXML file. For
more information about including external ActionScript files in Flex applications, see “Using
ActionScript” in
Developing Flex Applications
.
Содержание 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 ...