With Flex 4 we now have a new way of using two-ways data binding by using the @ character in conjunction with the curly braces syntax. In the previous version of Flex if we needed to have a two way binding we had to specify this in both the tags that were bound together:
<mx:TextInput id="txt1" text="{txt2.text}"/> <mx:TextInput id="txt2" text="{txt1.text}"/> |
Now, in Flex 4 we only specify the binding in one tag, and leave the other tag empty. In addition to this you must use the @ character just before you start the curly brace. This is how it works now with Flex 4:
<s:TextInput id="txt1" text="@{txt2.text}" /> <s:TextInput id="txt2" /> |
Here is the complete working example:
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" viewSourceURL="srcview/index.html"> <s:layout> <s:VerticalLayout horizontalAlign="center" paddingTop="10"/> </s:layout> <s:TextInput id="txt1" text="@{txt2.text}" /> <s:TextInput id="txt2" /> </s:Application> |
View Source is enabled in the above example. To view the source files right click on the swf and choose “View Source” from the context menu.