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.

The Object.watch() method cannot watch getter/setter properties. Getter/setter properties<br />

operate through lazy evaluation-- the value of the property is not determined until the<br />

property is actually queried. Lazy evaluation is often efficient because the property is not<br />

constantly updated; it is, rather, evaluated when needed. However, Object.watch() needs to<br />

evaluate a property to determine whether to invoke the callback function. To work with a<br />

getter/setter property, Object.watch() needs to evaluate the property constantly, which is<br />

inefficient.<br />

Generally, predefined ActionScript properties, such as _x, _y, _width, <strong>and</strong> _height, are<br />

getter/setter properties <strong>and</strong> cannot be watched with Object.watch().<br />

Parameters<br />

name:String - A string; the name of the object property to watch.<br />

callback:Function - The function to invoke when the watched property changes. This<br />

parameter is a function object, not a function name as a string. The form of callback is<br />

callback(prop, oldVal, newVal, userData).<br />

userData:Object [optional] - An arbitrary piece of ActionScript data that is passed to the<br />

callback method. If the userData parameter is omitted, undefined is passed to the callback<br />

method.<br />

Returns<br />

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

Example<br />

The following example uses watch() to check whether the speed property exceeds the speed<br />

limit:<br />

// Create a new object<br />

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

// Add a property that tracks speed<br />

myObject.speed = 0;<br />

// Write the callback function to be executed if the speed property changes<br />

var speedWatcher:Function = function(prop, oldVal, newVal, speedLimit) {<br />

// Check whether speed is above the limit<br />

if (newVal > speedLimit) {<br />

trace ("You are speeding.");<br />

}<br />

else {<br />

trace ("You are not speeding.");<br />

}<br />

536 ActionScript classes

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

Saved successfully!

Ooh no, something went wrong!