Flex中的可绑定属性更改事件

Bil*_*hla 1 actionscript-3 flex4.5

任何人都可以帮我解决这个谜团:

我有一个名为Box.as的组件,它具有以下两个属性,并定义了它们的getter和setter:

private var _busy:Boolean;
private var _errorMessage:String;
Run Code Online (Sandbox Code Playgroud)

在使用此组件的MXML中,我将其定义如下:

<components:Box skinClass="skins.components.BoxSkin"
                busy="{presenter.boxBusy}"
        errorMessage="{presenter.boxErrorMessage}"/>
Run Code Online (Sandbox Code Playgroud)

其中presenter变量在MXML中定义,而Presenter类的boxBusy和boxErrorMessage变量定义为可绑定属性更改事件:

[Bindable(event="propertyChange")]
function get boxBusy():Boolean;
function set boxBusy(value:Boolean):void;

[Bindable(event="propertyChange")]
function get boxErrorMessage():String;
function set boxErrorMessage(value:String):void;
Run Code Online (Sandbox Code Playgroud)

问题是,无论何时我为演示者更改boxErrorMessage,我都会看到MXML中的影响但是当我更改boxBusy时根本没有任何反应.我需要做一些额外的布尔变量吗?

非常感谢提前.

Lee*_*Lee 8

你应该忽略(event="propertyChange")从规范[Bindable]上两元数据标签boxBusyboxErrorMessage.另外,请确保将get/set方法声明为public.

所以,该属性boxBusy看起来像这样:

[Bindable]
public function get boxBusy():Boolean {  return _busy; }
public function set boxBusy(value:Boolean):void {  _busy = value; }
Run Code Online (Sandbox Code Playgroud)

当你符合条件[Bindable](event="..."),你告诉Flex,"每当更新绑定时,我都会发送命名事件".

如果省略事件规范,则flex假定事件已命名propertyChange.但事实并非如此.它还使用生成的代码自动"包装"您的setter,该代码'propertyChange'在使用setter修改值时透明地调度事件.这在adobe livedocs中有更详细的描述.

所以......通过明确指定(event="propertyChange"),可以禁用flex的默认行为.即使您使用默认事件名称,flex也不会生成包装器代码 - 相反,它会指望您在适当的时间从代码中调度事件.

我想你的boxErrorMessage属性似乎正在工作,因为[Bindable]你的类的其他属性在同一个传递中发生变化 - 因此调度propertyChange,并导致boxErrorMessage绑定更新为副作用.