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 />

In the following example, you define a Team class. The Team class includes get/set methods<br />

that let you retrieve <strong>and</strong> set properties within the class:<br />

class Team {<br />

var teamName:String;<br />

var teamCode:String;<br />

var teamPlayers:Array = new Array();<br />

function Team(param_name:String, param_code:String) {<br />

this.teamName = param_name;<br />

this.teamCode = param_code;<br />

}<br />

function get name():String {<br />

return this.teamName;<br />

}<br />

function set name(param_name:String):Void {<br />

this.teamName = param_name;<br />

}<br />

}<br />

Enter the following ActionScript in a frame on the Timeline:<br />

var giants:Team = new Team("San Fran", "SFO");<br />

trace(giants.name);<br />

giants.name = "San Francisco";<br />

trace(giants.name);<br />

/* output:<br />

San Fran San Francisco */<br />

When you trace giants.name, you use the get method to return the value of the property.<br />

See also<br />

addProperty (Object.addProperty method)<br />

if statement<br />

if(condition) { statement(s); }<br />

Evaluates a condition to determine the next action in a SWF file. If the condition is true,<br />

Flash runs the statements that follow the condition inside curly braces ({}). If the condition is<br />

false, Flash skips the statements inside the curly braces <strong>and</strong> runs the statements following<br />

the curly braces. Use the if statement along with the else <strong>and</strong> else if statements to create<br />

branching logic in your scripts.<br />

The curly braces ({}) used to enclose the block of statements to be executed by the if<br />

statement are not necessary if only one statement will execute.<br />

186 ActionScript language elements

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

Saved successfully!

Ooh no, something went wrong!