【问题标题】:How to remove a Binding in Flex 4.5?如何在 Flex 4.5 中删除绑定?
【发布时间】:2011-08-26 08:54:08
【问题描述】:

我有这个代码:

BindingUtils.bindProperty(trollImage, "width", vslider, "value");
BindingUtils.bindProperty(trollImage, "height", vslider, "value");

并且适当的组件是用 MXML 编写的:

<s:Image id="trollImage" source="http://clansql.comoj.com/meme/trollface-square.png"/>
<s:VSlider id="vslider" height="400" maximum="600" minimum="5" value="400"/>

我通过按一个按钮来创建绑定。在我按下另一个按钮后,绑定应该被删除。

我找到了 Flex 3.5 here 的解决方案,但这不适用于 Flex 4.5,因为组件没有 _bindings 属性。 Flex 4.5 中的情况如何?有人可以告诉我吗?

非常感谢!

【问题讨论】:

    标签: apache-flex actionscript-3 binding flex4.5


    【解决方案1】:

    无论如何,Flex 3.5 解决方案对我来说看起来很老套。

    您应该使用ChangeWatcher#unWatch()BindingUtils#bindProperty() 函数返回一个 ChangeWatcher 实例。

    在你的情况下会导致这样的结果:

    var widthWatcher:ChangeWatcher = 
        BindingUtils.bindProperty(trollImage, "width", vslider, "value");
    var heightWatcher:ChangeWatcher = 
        BindingUtils.bindProperty(trollImage, "height", vslider, "value");
    
    widthWatcher.unWatch();
    heightWatcher.unWatch();
    

    【讨论】:

    • 非常感谢!这正是我想要的。
    【解决方案2】:

    根据the documentation BindingUtils.bindProperty() 返回ChangeWatcher instance 您应该使用它来销毁绑定。伪代码如下所示:

    private var trollImageWidthWatcher:ChangeWatcher;
    private var trollImageHeightWatcher:ChangeWatcher;
    
    private function firstButtonClickHandler(event:MouseEvent):void
    {
        trollImageWidthWatcher = BindingUtils.bindProperty(trollImage, "width", vslider, "value");
        trollImageHeightWatcher = BindingUtils.bindProperty(trollImage, "height", vslider, "value");
    }
    
    private function secondButtonClickHandler(event:MouseEvent):void
    {
        trollImageWidthWatcher.unwatch();
        trollImageHeightWatcher.unwatch();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多