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.

Example<br />

See the example for Object.watch().<br />

See also<br />

watch (Object.watch method), addProperty (Object.addProperty method)<br />

valueOf (Object.valueOf method)<br />

public valueOf() : Object<br />

Returns the primitive value of the specified object. If the object does not have a primitive<br />

value, the object is returned.<br />

Returns<br />

Object - The primitive value of the specified object or the object itself.<br />

Example<br />

The following example shows the return value of valueOf() for a generic object (which does<br />

not have a primitive value) <strong>and</strong> compares it to the return value of toString(). First, create a<br />

generic object. Second, create a new Date object set to February 1, 2004, 8:15 AM. The<br />

toString() method returns the current time in human-readable form. The valueOf() method<br />

returns the primitive value in milliseconds. Third, create a new Array object containing two<br />

simple elements. Both toString() <strong>and</strong> valueOf() return the same value: one,two:<br />

// Create a generic object<br />

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

trace(myObject.valueOf()); // output: [object Object]<br />

trace(myObject.toString()); // output: [object Object]<br />

The following examples show the return values for the built-in classes Date <strong>and</strong> Array, <strong>and</strong><br />

compares them to the return values of Object.toString():<br />

// Create a new Date object set to February 1, 2004, 8:15 AM<br />

// The toString() method returns the current time in human-readable form<br />

// The valueOf() method returns the primitive value in milliseconds<br />

var myDate:Date = new Date(2004,01,01,8,15);<br />

trace(myDate.toString()); // output: Sun Feb 1 08:15:00 GMT-0800 2004<br />

trace(myDate.valueOf()); // output: 1075652100000<br />

// Create a new Array object containing two simple elements<br />

// In this case both toString() <strong>and</strong> valueOf() return the same value: one,two<br />

var myArray:Array = new Array("one", "two");<br />

trace(myArray.toString()); // output: one,two<br />

trace(myArray.valueOf()); // output: one,two<br />

534 ActionScript classes

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

Saved successfully!

Ooh no, something went wrong!