Example
The following example creates a Login class that demonstrates how the
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
function triggers only when you pass it a value, as shown in the line:
gus.username = "Rupert";
See also
get statement
set variable statement
set("variableString",expression)
Assigns a value to a variable. A variable is a container that holds data. The container is always
the same, but the contents can change. By changing the value of a variable as the SWF file
plays, you can record and save information about what the user has done, record values that
change as the SWF file plays, or evaluate whether a condition is
function executes when the value is traced. The
get
keyword can be
set
set
or
.
true
false
Statements
211
Need help?
Do you have a question about the FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE and is the answer not in the manual?