User Guide

224 ActionScript language elements
See also
function statement
set statement
function set property(varName) {
// your statements here
}
Permits implicit setting of properties associated with objects based on classes you have defined
in external class files. Using implicit set methods lets you modify the value of an object's
property without accessing the property directly. Implicit get/set methods are syntactic
shorthand for the
Object.addProperty() method in ActionScript 1.0.
Availability: ActionScript 2.0; Flash Player 6
Parameters
property:String - Word that refers to the property that set will access; this value must be
the same as the value used in the corresponding
get command.
Example
The following example creates a Login class that demonstrates how the
set keyword can be
used to set private variables:
class Login {
private var loginUserName:String;
private var loginPassword:String;
public function Login(param_username:String, param_password:String) {
this.loginUserName = param_username;
this.loginPassword = param_password;
}
public function get username():String {
return this.loginUserName;
}
public function set username(param_username:String):Void {
this.loginUserName = param_username;
}
public function set password(param_password:String):Void {
this.loginPassword = param_password;
}
}
In a FLA or AS file that is in the same directory as Login.as, enter the following ActionScript
in Frame 1 of the Timeline:
var gus:Login = new Login("Gus", "Smith");
trace(gus.username); // output: Gus