ActionScript中的双向数据绑定导致堆栈溢出
我将两个 AutoCompleteModified 对象相互绑定;意思是你输入 它在一个中选择正确的对象,在另一个中选择正确的对象。当我时它工作得很好 在 MXML 中定义它:
但是,用户可以向网格添加新行,然后我设置绑定并 通过动作脚本对象,它给出了“未定义”错误: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 = '名称';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'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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在尝试做同样的事情。它适用于 MXML,但不适用于 AS。例如,这是有效的:
如果我滚动其中一个文本区域,则另一个也会滚动。但是,尝试在 actionscript 中执行相同的操作会导致堆栈溢出(无限循环),
我使用了 -keep- generated-actionscript 编译器选项,并查看了生成的 asctionscript mxml 示例,它创建了几个 mx.binding.Binding 对象,看起来关键是设置 twoWayCounterpart 属性。我还没有尝试模仿该代码,但它可能会对您有所帮助。
I'm trying to do the same thing. It works in MXML but not in AS. For example, this works:
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)
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.
由于这两个组件像这样相互绑定,我对您看到这一点并不感到惊讶,更令我惊讶的是它是通过 mxml 工作的。
您是否尝试过将bindProperty中的(可选)第五个参数更改为true?该参数是 commitOnly 并且默认为 false。这可能会解决你的问题。
另一种方法可能是使用中间变量来存储所选项目并将组件绑定到该变量。
希望有帮助。
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.