User Guide

1008 ActionScript classes
The Object.watch() method cannot watch getter/setter properties. Getter/setter properties
operate through lazy evaluation-- the value of the property is not determined until the
property is actually queried. Lazy evaluation is often efficient because the property is not
constantly updated; it is, rather, evaluated when needed. However,
Object.watch() needs to
evaluate a property to determine whether to invoke the
callback function. To work with a
getter/setter property,
Object.watch() needs to evaluate the property constantly, which is
inefficient.
Generally, predefined ActionScript properties, such as
_x, _y, _width, and _height, are
getter/setter properties and cannot be watched with
Object.watch().
Availability: ActionScript 1.0; Flash Player 6
Parameters
name:String - A string; the name of the object property to watch.
callback:Function - The function to invoke when the watched property changes. This
parameter is a function object, not a function name as a string. The form of
callback is
callback(prop, oldVal, newVal, userData).
userData:Object [optional] - An arbitrary piece of ActionScript data that is passed to the
callback method. If the userData parameter is omitted, undefined is passed to the callback
method.
Returns
Boolean - A Boolean value: true if the watchpoint is created successfully, false otherwise.
Example
The following example uses
watch() to check whether the speed property exceeds the speed
limit:
// Create a new object
var myObject:Object = new Object();
// Add a property that tracks speed
myObject.speed = 0;
// Write the callback function to be executed if the speed property changes
var speedWatcher:Function = function(prop, oldVal, newVal, speedLimit) {
// Check whether speed is above the limit
if (newVal > speedLimit) {
trace ("You are speeding.");
}
else {
trace ("You are not speeding.");
}