Adobe® Flex® 4 Language Reference
Show Packages and Classes List |  Packages  |  Classes  |  Index  |  Appendixes
mx.binding.utils 
ChangeWatcher 
Packagemx.binding.utils
Classpublic class ChangeWatcher
InheritanceChangeWatcher Inheritance Object

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

The ChangeWatcher class defines utility methods that you can use with bindable Flex properties. These methods let you define an event handler that is executed whenever a bindable property is updated.

See also



Public Properties
 PropertyDefined By
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
  useWeakReference : Boolean
(default = false) Determines whether the reference to the host is strong or weak.
ChangeWatcher
Public Methods
 MethodDefined By
  
ChangeWatcher(access:Object, handler:Function, commitOnly:Boolean = false, next:ChangeWatcher = null)
Constructor.
ChangeWatcher
  
canWatch(host:Object, name:String, commitOnly:Boolean = false):Boolean
[static] Lets you determine if the host exposes a data-binding event on the property.
ChangeWatcher
  
getEvents(host:Object, name:String, commitOnly:Boolean = false):Object
[static] Returns all binding events for a bindable property in the host object.
ChangeWatcher
  
Retrieves the current value of the watched property or property chain, or null if the host object is null.
ChangeWatcher
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
  
Returns true if each watcher in the chain is attached to at least one change event.
ChangeWatcher
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
  
reset(newHost:Object):void
Resets this ChangeWatcher instance to use a new host object.
ChangeWatcher
  
Sets the handler function.
ChangeWatcher
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
  
Detaches this ChangeWatcher instance, and its handler function, from the current host.
ChangeWatcher
 Inherited
Returns the primitive value of the specified object.
Object
  
watch(host:Object, chain:Object, handler:Function, commitOnly:Boolean = false, useWeakReference:Boolean = false):ChangeWatcher
[static] Creates and starts a ChangeWatcher instance.
ChangeWatcher
Property Detail

useWeakReference

property
public var useWeakReference:Boolean

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

(default = false) Determines whether the reference to the host is strong or weak. A strong reference (the default) prevents the host from being garbage-collected. A weak reference does not.

Constructor Detail

ChangeWatcher

()Constructor
public function ChangeWatcher(access:Object, handler:Function, commitOnly:Boolean = false, next:ChangeWatcher = null)

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Constructor. Not for public use. This method is called only from the watch() method. See the watch() method for parameter usage.

Parameters
access:Object
 
handler:Function
 
commitOnly:Boolean (default = false)
 
next:ChangeWatcher (default = null)
Method Detail

canWatch

()method
public static function canWatch(host:Object, name:String, commitOnly:Boolean = false):Boolean

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Lets you determine if the host exposes a data-binding event on the property.

Parameters

host:Object — The host of the property. See the watch() method for more information.
 
name:String — The name of the property, or property chain. See the watch() method for more information.
 
commitOnly:Boolean (default = false) — Set to true if the handler should be called only on committing change events. See the watch() method for more information.

Returns
Booleantrue if host exposes any change events on name.

getEvents

()method 
public static function getEvents(host:Object, name:String, commitOnly:Boolean = false):Object

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Returns all binding events for a bindable property in the host object.

Parameters

host:Object — The host of the property. See the watch() method for more information.
 
name:String — The name of the property, or property chain. See the watch() method for more information.
 
commitOnly:Boolean (default = false) — Controls inclusion of non-committing change events in the returned value.

Returns
Object — Object of the form { eventName: isCommitting, ... } containing all change events for the property.

getValue

()method 
public function getValue():Object

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Retrieves the current value of the watched property or property chain, or null if the host object is null. For example:

      watch(obj, ["a","b","c"], ...).getValue() === obj.a.b.c
      

Returns
Object — The current value of the watched property or property chain.

isWatching

()method 
public function isWatching():Boolean

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Returns true if each watcher in the chain is attached to at least one change event. Note that the isWatching() method varies with host, since different hosts may expose different change events for the watcher's chosen property.

Returns
Booleantrue if each watcher in the chain is attached to at least one change event.

reset

()method 
public function reset(newHost:Object):void

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Resets this ChangeWatcher instance to use a new host object. You can call this method to reuse a watcher instance on a different host.

Parameters

newHost:Object — The new host of the property. See the watch() method for more information.

setHandler

()method 
public function setHandler(handler:Function):void

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Sets the handler function.

Parameters

handler:Function — The handler function. This argument must not be null.

unwatch

()method 
public function unwatch():void

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Detaches this ChangeWatcher instance, and its handler function, from the current host. You can use the reset() method to reattach the ChangeWatcher instance, or watch the same property or chain on a different host object.

watch

()method 
public static function watch(host:Object, chain:Object, handler:Function, commitOnly:Boolean = false, useWeakReference:Boolean = false):ChangeWatcher

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Creates and starts a ChangeWatcher instance. A single ChangeWatcher instance can watch one property, or a property chain. A property chain is a sequence of properties accessible from a host object. For example, the expression obj.a.b.c contains the property chain (a, b, c).

Parameters

host:Object — The object that hosts the property or property chain to be watched. You can use the use the reset() method to change the value of the host argument after creating the ChangeWatcher instance.
 
chain:Object — A value specifying the property or chain to be watched. Legal values are:
  • A String containing the name of a public bindable property of the host object.
  • An Object in the form: { name: property name, getter: function(host) { return host[name] } }. The Object contains the name of a public bindable property, and a function which serves as a getter for that property.
  • A non-empty Array containing any combination of the first two options. This represents a chain of bindable properties accessible from the host. For example, to watch the property host.a.b.c, call the method as: watch(host, ["a","b","c"], ...).

Note: The property or properties named in the chain argument must be public, because the describeType() method suppresses all information about non-public properties, including the bindability metadata that ChangeWatcher scans to find the change events that are exposed for a given property. However, the getter function supplied when using the { name, getter } argument form described above can be used to associate an arbitrary computed value with the named (public) property.

 
handler:Function — An event handler function called when the value of the watched property (or any property in a watched chain) is modified. The modification is signaled when any host object in the watcher chain dispatches the event that has been specified in that host object's [Bindable] metadata tag for the corresponding watched property. The default event is named propertyChange.

The event object dispatched by the bindable property is passed to this handler function without modification. By default, Flex dispatches an event object of type PropertyChangeEvent. However, you can define your own event type when you use the [Bindable] metadata tag to define a bindable property.

 
commitOnly:Boolean (default = false) — Set to true if the handler should be called only on committing change events; set to false if the handler should be called on both committing and non-committing change events. Note: the presence of non-committing change events for a property is indicated by the [NonCommittingChangeEvent(<event-name>)] metadata tag. Typically these tags are used to indicate fine-grained value changes, such as modifications in a text field prior to confirmation.
 
useWeakReference:Boolean (default = false) — (default = false) Determines whether the reference to the host is strong or weak. A strong reference (the default) prevents the host from being garbage-collected. A weak reference does not.

Returns
ChangeWatcher — The ChangeWatcher instance, if at least one property name has been specified to the chain argument; null otherwise. Note that the returned watcher is not guaranteed to have successfully discovered and attached itself to change events, since none may have been exposed on the given property or chain by the host. You can use the isWatching() method to determine the watcher's state.

See also