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.

The following example shows how to override toString() in a custom class. First create a<br />

text file named Vehicle.as that contains only the Vehicle class definition <strong>and</strong> place it into your<br />

Classes folder inside your Configuration folder.<br />

// contents of Vehicle.as<br />

class Vehicle {<br />

var numDoors:Number;<br />

var color:String;<br />

function Vehicle(param_numDoors:Number, param_color:String) {<br />

this.numDoors = param_numDoors;<br />

this.color = param_color;<br />

}<br />

function toString():String {<br />

var doors:String = "door";<br />

if (this.numDoors > 1) {<br />

doors += "s";<br />

}<br />

return ("A vehicle that is " + this.color + " <strong>and</strong> has " + this.numDoors +<br />

" " + doors);<br />

}<br />

}<br />

// code to place into a FLA file<br />

var myVehicle:Vehicle = new Vehicle(2, "red");<br />

trace(myVehicle.toString());<br />

// output: A vehicle that is red <strong>and</strong> has 2 doors<br />

// for comparison purposes, this is a call to valueOf()<br />

// there is no primitive value of myVehicle, so the object is returned<br />

// giving the same output as toString().<br />

trace(myVehicle.valueOf());<br />

// output: A vehicle that is red <strong>and</strong> has 2 doors<br />

unwatch (Object.unwatch method)<br />

public unwatch(name:String) : Boolean<br />

Removes a watchpoint that Object.watch() created. This method returns a value of true if<br />

the watchpoint is successfully removed, false otherwise.<br />

Parameters<br />

name:String - A string; the name of the object property that should no longer be watched.<br />

Returns<br />

Boolean - A Boolean value: true if the watchpoint is successfully removed, false otherwise.<br />

Object 533

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

Saved successfully!

Ooh no, something went wrong!