View comments | RSS feed
Packagemx.binding.utils
Classpublic class BindingUtils
InheritanceBindingUtils Inheritance Object

The BindingUtils class defines utility methods for performing data binding from ActionScript. You can use the methods defined in this class to configure data bindings.

See also

About data binding


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
Public Methods
 MethodDefined by
  
bindProperty(site:Object, prop:String, host:Object, chain:Object, commitOnly:Boolean = false):ChangeWatcher
[static] Binds a public property, prop on the site Object, to a bindable property or property chain.
BindingUtils
  
bindSetter(setter:Function, host:Object, chain:Object, commitOnly:Boolean = false):ChangeWatcher
[static] Binds a setter function, setter, to a bindable property or property chain.
BindingUtils
 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
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Method detail
bindProperty()method
public static function bindProperty(site:Object, prop:String, host:Object, chain:Object, commitOnly:Boolean = false):ChangeWatcher

Binds a public property, prop on the site Object, to a bindable property or property chain. If a ChangeWatcher instance is successfully created, prop is initialized to the current value of chain.

Parameters
site:Object — The Object defining the property to be bound to chain.
 
prop:String — The name of the public property defined in the site Object to be bound. The property will receive the current value of chain, when the value of chain changes.
 
host:Object — The object that hosts the property or property chain to be watched.
 
chain:Object — A value specifying the property or chain to be watched. Legal values are:
  • String containing the name of a public bindable property of the host object.
  • An Object in the form: { name: property name, access: function(host) { return host[name] } }. This Object must contain the name of, and an accessor function for, a non-public bindable property of the host object.
  • A non-empty Array containing a combination of the first two options that 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"], ...).
 
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.

Returns
ChangeWatcher — A ChangeWatcher instance, if at least one property name has been specified to the chain argument; null otherwise.
bindSetter()method 
public static function bindSetter(setter:Function, host:Object, chain:Object, commitOnly:Boolean = false):ChangeWatcher

Binds a setter function, setter, to a bindable property or property chain. If a ChangeWatcher instance is successfully created, the setter function is invoked with current value of chain.

Parameters
setter:Function — Setter method to invoke with an argument of the current value of chain when that value changes.
 
host:Object — The host of the property. See the bindProperty() method for more information.
 
chain:Object — The name of the property, or property chain. See the bindProperty() method for more information.
 
commitOnly:Boolean (default = false) — Set to true if the handler should be called only on committing change events. See the bindProperty() method for more information.

Returns
ChangeWatcher — A ChangeWatcher instance, if at least one property name has been specified to the chain argument; null otherwise.




Comments


TankMan89 said on Jul 2, 2006 at 9:51 AM :
An example would be good here. An example of how to make something bindable, and bind to it, entirely in actionscript, not mxml.
smgilson said on Jul 3, 2006 at 5:18 AM :
There are examples in the doc here:

http://livedocs.macromedia.com/flex/2/docs/00001043.html

http://livedocs.macromedia.com/flex/2/docs/00001044.html

Stephen
R9N1 said on Jul 19, 2006 at 1:30 AM :
Can I have a working example on defining a binding to a setter function in actionscript? Let's say I want to implement this in actionscript:

<mx:Binding source="myTextInput.text" destination="handleChangeText" />

private function set handleChangeText( newText: String ): void {...}

Thanks
smgilson said on Jul 19, 2006 at 11:10 AM :
Here's an example using bindSetter():

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script>
<![CDATA[

import mx.binding.utils.*;
import mx.events.FlexEvent;

<!-- Event listener to configure binding with a setter. -->
public function mySetterBindingInline(event:FlexEvent):void {
var watcherSetter:ChangeWatcher = BindingUtils.bindSetter(function(v:String):void { taSetter1.text = v}, tiSetter1, "text");
}

// Set method.
public function setMyString(val:String):void {
taSetter2.text = val;
}

<!-- Event listener to configure binding with a setter. -->
public function mySetterBinding(event:FlexEvent):void {
var watcherSetter:ChangeWatcher = BindingUtils.bindSetter(setMyString, tiSetter2, "text");
}
]]>
</mx:Script>

<mx:Panel title="My Application" paddingTop="10" paddingBottom="10"
paddingLeft="10" paddingRight="10" >

<mx:Label text="Bind Setter using inline setter"/>
<mx:TextInput id="tiSetter1" text="Hello Setter" />
<mx:TextArea id="taSetter1" initialize="mySetterBindingInline(event);"/>


<mx:Label text="Bind Setter using setter method"/>
<mx:TextInput id="tiSetter2" text="Hello Setter" />
<mx:TextArea id="taSetter2" initialize="mySetterBinding(event);"/>

</mx:Panel>
</mx:Application>
Ray Greenwell said on Sep 5, 2006 at 3:45 PM :
The documentation for bindProperty() is incorrect. If an Object is specified for the chain object, the name of the property containing the accessor function should be "getter" not "access".
smgilson said on Sep 6, 2006 at 7:35 AM :
You are correct: the property name is 'getter'. This is also true for the ChangeWatcher.watch() method.

Stephen Gilson
Flex Doc Team
mikeSibbald said on Jun 21, 2007 at 12:11 AM :
Check it out.... some binding samples...:

http://labs.flexcoders.nl/?p=24

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flex/2/langref/mx/binding/utils/BindingUtils.html