AS3中的Flex绑定 - 否定布尔值

Doo*_*Mat 5 apache-flex checkbox binding boolean actionscript-3

我将复选框绑定到控件上的属性.一切都很好,但我需要将复选框绑定到另一个属性,并且值必须与chkbox.checked相反.

BindingUtils.bindProperty(obj, "propertyBool", checkBox, "selected");
Run Code Online (Sandbox Code Playgroud)

我需要这样的东西......

BindingUtils.bindProperty(obj, "propertyBool", checkBox, "!selected");
Run Code Online (Sandbox Code Playgroud)

但我不知道如何在AS3中这样做.

Ros*_*son 6

您可以使用BindingUtils的bindSetter方法.它与bindProperty方法的工作原理基本相同,但它会触发一个方法,该方法将您要绑定的属性的值作为参数.

类似于以下内容:

BindingUtils.bindSetter(propertyBoolListener, checkBox, "selected");

private function propertyBoolListener(value:Boolean):void
{
    obj.propertyBool = !value;
}
Run Code Online (Sandbox Code Playgroud)