EasyManua.ls Logo

MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE - Set Variable Statement

MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE
780 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Statements 211
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
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";
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
true or false.

Table of Contents

Related product manuals