tags:

views:

67

answers:

2

Hi -

I'm binding two AutoCompleteModified objects to one another; meaning you type in one and it selects the correct object in the other. It works fine when I define it in MXML:

However, a user can add a new row to a Grid and then I set up the binding and objects via actionscript and it gives an 'undefined' error: ChangeWatcher line 427/wrapHandler.

var innerHBox:HBox = new HBox();

var dtc_acm:AutoCompleteModified = new AutoCompleteModified(); dtc_acm.dataProvider = data2; dtc_acm.labelField = 'id';

var cp_acm:AutoCompleteModified = new AutoCompleteModified(); cp_acm.dataProvider = data2; cp_acm.labelField = 'name';cp_acm.width = this.CP1.width;

BindingUtils.bindProperty( dtc_acm,'selectedIndex',cp_acm,'selectedIndex' );

BindingUtils.bindProperty( cp_acm,'selectedItem',dtc_acm,'selectedItem' );

innerHBox.addChild( dtc_acm ); innerHBox.addChild( cp_acm );

I don't understand what may be happening here. Can anyone see any potential problems in my code? If I only keep it 1-way binding then it works fine. But both throw this error. Is there something about not only doing it 2-way in actionscript, but adding components that aren't on the stage yet?

Thank you kindly for any helpful tips,

Matt

A: 

Since the two components are bound to each other like this I'm not surprised you are seeing this, I'm more surprised that it worked via mxml.

Have you tried changing the (optional) 5th parameter in bindProperty to true? That parameter is commitOnly and defaults to false. That may fix your problem.

Another approach could be to have an intermediary variable to store the selected item and bind your components to that variable.

Hope that helps.

Wade Mueller
I'll give the intermediary variable a shot but I don't see what's wrong with the AS code? All docs I've read say that 2-way binding you need to define each binding. What's wrong with how I did it? Thank you for your response. I'm just trying to figure out what is wrong with binding the components together like this. Is there a better approach? Thank you for your help.
fumeng
A: 

I'm trying to do the same thing. It works in MXML but not in AS. For example, this works:

<mx:TextArea id="t1" verticalScrollPosition="{t2.verticalScrollPosition}" height="200"/>
<mx:TextArea id="t2" verticalScrollPosition="{t1.verticalScrollPosition}" height="200"/>

If I scroll one of the TextAreas then the other one scrolls too. However, trying to do the same thing in actionscript causes a stack overflow (infinite loop)

BindingUtils.bindProperty( _t1, 'verticalScrollPosition', _t2, 'verticalScrollPosition' );
BindingUtils.bindProperty( _t2, 'verticalScrollPosition', _t1, 'verticalScrollPosition' );

I used the -keep-generated-actionscript compiler option and looked at the generated asctionscript for the mxml example and it creates a couple mx.binding.Binding objects and it looks like the key is setting the twoWayCounterpart property. I haven't tried mimicking that code yet but it might help you.

slugolicious