03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example<br />

The following example creates a Login class that demonstrates how the set keyword can be<br />

used to set private variables:<br />

class Login {<br />

private var loginUserName:String;<br />

private var loginPassword:String;<br />

public function Login(param_username:String, param_password:String) {<br />

this.loginUserName = param_username;<br />

this.loginPassword = param_password;<br />

}<br />

public function get username():String {<br />

return this.loginUserName;<br />

}<br />

public function set username(param_username:String):Void {<br />

this.loginUserName = param_username;<br />

}<br />

public function set password(param_password:String):Void {<br />

this.loginPassword = param_password;<br />

}<br />

}<br />

In a FLA or AS file that is in the same directory as Login.as, enter the following ActionScript<br />

in Frame 1 of the Timeline:<br />

var gus:Login = new Login("Gus", "Smith");<br />

trace(gus.username); // output: Gus<br />

gus.username = "Rupert";<br />

trace(gus.username); // output: Rupert<br />

In the following example, the get function executes when the value is traced. The set<br />

function triggers only when you pass it a value, as shown in the line:<br />

gus.username = "Rupert";<br />

See also<br />

getProperty function<br />

set variable statement<br />

set("variableString",expression)<br />

Assigns a value to a variable. A variable is a container that holds data. The container is always<br />

the same, but the contents can change. By changing the value of a variable as the SWF file<br />

plays, you can record <strong>and</strong> save information about what the user has done, record values that<br />

change as the SWF file plays, or evaluate whether a condition is true or false.<br />

196 ActionScript language elements

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!