« How to enable communication between AIR and Skype through Merapi | Main | Flex Skin: Adobe Flash and Adobe Illustrator interaction »

ChangeEvent vs Bindable, multiple change events for binding

When you need to define binding based on different custom events you have to use the ChangeEvent metadata tag. The ChangeEvent metadata keyword generates one or more component events when changes are made to one of its properties.

The ChangeEvent metadata keyword has the following syntax:

[ChangeEvent("event_name"[,...)]
property_declaration or a get/set function

You can register multiple change events in the metadata so that more than one event is generated when the property changes, as the following example shows:

[ChangeEvent("change1")]
[ChangeEvent("change2")]
[ChangeEvent("change3")]

Any one of those events indicates a change to the variable. They do not have to occur all to indicate a change.

So lets have a look on how to create different bindings based on different events:
First define the bindable property through the ChangeEvent metadata:

[ChangeEvent("change1")]
[ChangeEvent("change2")]
[ChangeEvent("change3")]
public var myVar:String = "";

Now we need to define some change cases:

Case 1: Change myVar and dispatch the 'change1' event

<mx:Label text="Change myVar and dispatch the 'change1' event:"/>
<mx:TextInput change="myVar = txtArea.text; dispatchEvent( new Event( 'change1' ) );" id="txtArea"/>

Case 2 Change myVar and dispatch the 'change2' event

<mx:Label text="Change myVar and dispatch the 'change2' event:"/>
<mx:TextInput change="myVar = txtArea2.text; dispatchEvent( new Event( 'change2' ) );" id="txtArea2"/>

Case 3 Change myVar and don't dispatch any events:

<mx:Label text="Change myVar and don't dispatch any events:"/>
<mx:TextInput change="myVar = txtArea3.text;" id="txtArea3"/>

And finaly use a TextArea to bind the text property to myVar:

<mx:Label text="Bind text property to myVar:"/>
<mx:TextInput text="{myVar}"/>

You can see the full, working example (right click for source) here.

TrackBack

TrackBack URL for this entry:
http://blog.comtaste.com/mt-tb.cgi/78

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on January 27, 2009 2:19 PM.

The previous post in this blog was How to enable communication between AIR and Skype through Merapi.

The next post in this blog is Flex Skin: Adobe Flash and Adobe Illustrator interaction.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33