Skip to main content


Showing posts from January, 2009

Manually adding bindings between objects in Flex/AS3

I recently needed to manually create bindings in AS3 code between objects, and since MXML ultimately all is just AS3, I figured there had to be a way to do it.

<b>Binding in MXML</b>

Lets look at the following code...
    <mx:TextInput id="txtMyText?/>
    <mx:Label id="lblMyLabel? text="{txtMyText.text}"/>

Here you bind the text property of the TextInput to the label's text property so wh you type in the textInput, it reflects in the label.

<b>Binding in AS</b>

The key to this is a class called BindingUtils in the mx.binding.utils package. You can use this class as below:<more/>You have your components say in mxml as follows
    <mx:TextInput id="txtMyText? />
    <mx:Label id="lblMyLabel? />

Now you import the Binding utils and change watcher classes:
    import mx.binding.utils.BindingUtils;
    import mx.binding.utils.ChangeWat…