676
Chapter 2: ActionScript Language Reference
Object.watch()
Availability
Flash Player 6.
Usage
myObject
.watch(
prop:String
,
callback:Function
[,
userData:Object
] )
: Boolean
Parameters
prop
A string; the name of the object property to watch.
callback
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
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. This parameter
is optional.
Returns
A Boolean value:
true
if the watchpoint is created successfully,
false
otherwise.
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
myObject
as the
containing object.
Your can use the
return
statement in your
callback
method definition to affect the value of the
property you are watching. The value returned by your
callback
method is assigned to the
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
newVal
parameter.
•
If you are modifying the value of the property, return your own value.
•
If you want to prevent changes to the property, return the
oldVal
parameter.
If the
callback
method you define does not have a
return
statement, then the watched object
property is assigned a value of
undefined.
A watchpoint can filter (or nullify) the value assignment, by returning a modified
newval
(or
oldval
). If you delete a property for which a watchpoint has been set, that watchpoint does not
disappear. If you later recreate the property, the watchpoint is still in effect. To remove a
watchpoint, use the
Object.unwatch
method.
Only a single watchpoint can be registered on a property. Subsequent calls to
Object.watch()
on the same property replace the original watchpoint.
Summary of Contents for FLASH MX
Page 1: ...ActionScript Language Reference ...
Page 20: ...20 Contents ...
Page 24: ...24 Chapter 1 Introduction ...
Page 145: ...Button onKeyDown 145 See also Button onKeyUp ...
Page 202: ...202 Chapter 2 ActionScript Language Reference See also break default strict equality switch ...
Page 282: ...282 Chapter 2 ActionScript Language Reference See also break continue while ...
Page 383: ...LoadVars addRequestHeader 383 See also XML addRequestHeader ...
Page 388: ...388 Chapter 2 my_lv load place a valid URL pointing to a text file here ...
Page 463: ...Microphone setRate 463 See also Microphone rate ...
Page 469: ...Microphone silenceLevel 469 See also Microphone gain Microphone setSilenceLevel ...
Page 480: ...480 Chapter 2 ActionScript Language Reference See also Mouse addListener ...
Page 529: ...MovieClip globalToLocal 529 See also MovieClip getBounds MovieClip localToGlobal ...
Page 612: ...612 Chapter 2 ActionScript Language Reference See also MovieClipLoader onLoadStart ...
Page 623: ...NetConnection class 623 See also NetStream class Video attachVideo ...
Page 649: ...Number 649 See also NaN Number class ...
Page 679: ...on 679 on release trace X this _x trace Y this _y stopDrag See also onClipEvent ...
Page 683: ...onUpdate 683 buttonLabel textColor my_mc labelColor ...
Page 788: ...788 Chapter 2 ActionScript Language Reference See also private public ...
Page 1001: ...Video height 1001 my_mc _height my_mc my_video height See also MovieClip _height Video width ...
Page 1022: ...1022 Chapter 2 ActionScript Language Reference See also XML createElement ...
Page 1057: ...XML xmlDecl 1057 See also XML docTypeDecl XML toString ...
Page 1070: ...1070 Chapter 2 ActionScript Language Reference ...
Page 1104: ...1104 Appendix Deprecated Language Elements ...