The problem you are experiencing is caused by the fact that when the
player executes the line [ mf.foo = "bar" ], your text input is not even
created in your form yet. So, the foo->myText binding does nothing and
when the text input is finally created, the myText->foo binding executes
and thus overwrite what was in foo.
 
If you want to avoid this, you need to do:
 
protected var mf:MyForm = new MyForm();
mf.addEventListener(FlexEvent.CREATION_COMPLETE, formCreatedHandler);
addChild(mf);
 
protected function formCreatedHandler(event:FlexEvent):void {
    mf.removeEventListener(FlexEvent.CREATION_COMPLETE,
formCreatedHandler);
    mf.foo = "bar";
}

________________________________

From: [email protected] [mailto:[email protected]] On
Behalf Of enriirne
Sent: Wednesday, March 11, 2009 8:25 AM
To: [email protected]
Subject: [flexcoders] Question about binding and circular reference



Say I have this:

// MyForm.mxml
[Bindable]
public var foo:String;

<mx:Bindable source="foo" destination="myText.text"/>
<mx:Bindable source="myText.text" destination="foo"/>

<mx:TextInput id="myText"/>

Is there an elegant way to avoid that foo is cleared upon creation of
MyForm?
Indeed, if I do this in the main app:

var mf:MyForm = new MyForm();
mf.foo = "bar";
addChild(mf);

then myText is empty, probably because it's empty content is first
assigned to foo due to the second binding.
The real problem I'm trying to solve is to use the same value object to
show data to the user and to receive his/her changes.

Of course it works if I use two vos: say voIn and voOut, binding them
accordingly.

Any ideas?

Enri




Reply via email to