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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

{} object initializer operator<br />

object = { name1 : value1 , name2 : value2 ,... nameN : valueN }<br />

{expression1; [...expressionN]}<br />

Creates a new object <strong>and</strong> initializes it with the specified name <strong>and</strong> value property pairs. Using<br />

this operator is the same as using the new Object syntax <strong>and</strong> populating the property pairs<br />

using the assignment operator. The prototype of the newly created object is generically named<br />

the Object object.<br />

This operator is also used to mark blocks of contiguous code associated with flow control<br />

statements (for, while, if, else, switch) <strong>and</strong> functions.<br />

Oper<strong>and</strong>s<br />

object : Object - The object to create. name1,2,...N The names of the properties.<br />

value1,2,...N The corresponding values for each name property.<br />

Returns<br />

Object -<br />

Usage 1: An Object object.<br />

Usage 2: Nothing, except when a function has an explicit return statement, in which case the<br />

return type is specified in the function implementation.<br />

Example<br />

The first line of the following code creates an empty object using the object initializer ({})<br />

operator; the second line creates a new object using a constructor function:<br />

var object:Object = {};<br />

var object:Object = new Object();<br />

The following example creates an object account <strong>and</strong> initializes the properties name,<br />

address, city, state, zip, <strong>and</strong> balance with accompanying values:<br />

var account:Object = {name:"Macromedia, Inc.", address:"600 Townsend<br />

Street", city:"San Francisco", state:"California", zip:"94103",<br />

balance:"1000"};<br />

for (i in account) {<br />

trace("account." + i + " = " + account[i]);<br />

}<br />

The following example shows how array <strong>and</strong> object initializers can be nested within each<br />

other:<br />

var person:Object = {name:"Gina Vechio", children:["Ruby", "Chickie",<br />

"Puppa"]};<br />

156 ActionScript language elements

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

Saved successfully!

Ooh no, something went wrong!