Flex 3使用.as中的条件绑定布尔值

时间:2012-09-17 10:05:12

标签: actionscript-3 flex flex3

我想在actionscript中绑定一个带有条件的布尔值。这在mxml中是可能的,但是如何在actionscript上完成?

示例:

.mxml绑定:

enabled={(A_changed || B_changed  || C_changed || D_changed) && rs.selectedIndex !=-1}/>

.as binding:

BindingUtils.bindProperty(this.myBtn,'enabled',????);

谢谢, 戴夫

1 个答案:

答案 0 :(得分:0)

您的问题没有懒惰的解决方案 - Flex编译器在MXML绑定中进行了大量转换,这些转换在vanilla AS3中不可用。您必须将BindingUtils.bindSetter附加到所有属性。类似的东西:

var closure:Function = function(...triggers):void {
     enabled = (A_changed || B_changed || C_changed || D_changed) && rs.selectedIndex !=-1;
}
BindingUtils.bindSetter(closure, this, "A_changed");
BindingUtils.bindSetter(closure, this, "B_changed");
BindingUtils.bindSetter(closure, this, "C_changed");
BindingUtils.bindSetter(closure, this, "D_changed");
BindingUtils.bindSetter(closure, rs, "selectedIndex");