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 demonstrates how you can hide certain properties within a class using<br />

the private keyword. Create a new AS file called Login.as.<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 the same directory as Login.as, create a new FLA or AS document. Enter the following<br />

ActionScript in Frame 1 of the Timeline.<br />

import Login;<br />

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

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

trace(gus.password); // output: undefined<br />

trace(gus.loginPassword); // error<br />

Because loginPassword is a private variable, you cannot access it from outside the Login.as<br />

class file. Attempts to access the private variable generate an error message.<br />

See also<br />

public statement<br />

public statement<br />

class someClassName{ public var name; public function name() { // your<br />

statements here } }<br />

Note: To use this keyword, you must specify ActionScript 2.0 <strong>and</strong> Flash Player 6 or later in<br />

the Flash tab of your FLA file's Publish Settings dialog box. This keyword is supported only<br />

when used in external script files, not in scripts written in the Actions panel.<br />

Statements 193

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

Saved successfully!

Ooh no, something went wrong!