Flash CS3 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript language elements > Statements > 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
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.
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
gus.username = "Rupert";
trace(gus.username); // output: Rupert
In the following example, the get function executes when the value is traced. The set function triggers only when you pass it a value, as shown in the line:
gus.username = "Rupert";
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00001334.html