I need to bind a property to an edit control and have the control write its value back to the same property. The problem is, I'm setting the source value before the control is created:
<mx:Panel>
<mx:Script>
<![CDATA[
[Bindable] public var editedDocument: XML;
]]>
</mx:Script>
<mx:TextInput id="docLabel" text="{editedDocument.@label}"/>
<mx:Binding source="docLabel.text" destination="editedDocument.@label"/>
</mx:Panel>
I call this like so:
var xmlDoc: XML = <document label="some label" />;
var myPanel: MyPanel = new MyPanel();
myPanel.editedDocument = xmlDoc;
parent.addChild(myPanel);
What happens is this:
- the docLabel text field ends up blank (equal to "")
- the xmlDoc's @label attribute is set to ""
What I want is this:
- the docLabel text field should contain "some label"
- the xmlDoc's @label attribute should change only when the docLabel's text property changes.
How do I accomplish this, using Flex 3?
Edit
I have also tried this:
<mx:Panel>
<mx:Script>
<![CDATA[
[Bindable] public var editedDocument: XML;
]]>
</mx:Script>
<mx:TextInput id="docLabel"/>
<mx:Binding source="editedDocument.@label" destination="docLabel.text"/>
<mx:Binding source="docLabel.text" destination="editedDocument.@label"/>
</mx:Panel>
The result is the same.