Description
Method; registers an event handler to be invoked when a specified property of an ActionScript
object changes. When the property changes, the event handler is invoked with
containing object.
Your can use the
property you are watching. The value returned by your
watched object property. The value you choose to return depends on whether you wish to
monitor, modify or prevent changes to the property:
•
If you are merely monitoring the property, return the
•
If you are modifying the value of the property, return your own value.
•
If you want to prevent changes to the property, return the
If the
callback
property is assigned a value of
A watchpoint can filter (or nullify) the value assignment, by returning a modified
). If you delete a property for which a watchpoint has been set, that watchpoint does not
oldval
disappear. If you later recreate the property, the watchpoint is still in effect. To remove a
watchpoint, use the
Only a single watchpoint can be registered on a property. Subsequent calls to
on the same property replace the original watchpoint.
The
Object.watch()
1.2 and later. The primary difference is the
Object.watch()
parameter to the event handler and use it in the event handler.
The
Object.watch()
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,
determine whether to invoke the
Object.watch()
Generally, predefined ActionScript properties, such as
setter properties and cannot be watched with
Example
The following example uses
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
388
Chapter 6: ActionScript Core Classes
statement in your
return
method you define does not have a
undefined.
method.
Object.unwatch
method behaves similarly to the
that Netscape Navigator does not support. You can pass the
method cannot watch getter/setter properties. Getter/setter properties
callback
needs to evaluate the property constantly, which is inefficient.
to check whether the
watch()
method definition to affect the value of the
callback
callback
parameter.
newVal
oldVal
statement, then the watched object
return
Object.watch()
parameter, which is a Flash addition to
userData
needs to evaluate a property to
Object.watch()
function. To work with a getter/setter property,
,
,
_x
_y
_width
.
Object.watch()
speed
myObject
method is assigned to the
parameter.
newval
Object.watch()
function in JavaScript
userData
, and
, are getter/
_height
property exceeds the speed
as the
(or
Need help?
Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?