开发者

Bindable function without event name specified

开发者 https://www.devze.com 2023-02-18 20:17 出处:网络
What is the effect of making a function Bindable in flex without specifying event name with it? I have done this in my code and it seems to be working alright without any associated event (however it

What is the effect of making a function Bindable in flex without specifying event name with it? I have done this in my code and it seems to be working alright without any associated event (however it does generate a warning). If I remove the binding from such functions it will does effect the code and doesnt reflect the changes if the return value from the function changes.

Could someone explain me , how and why such Bindable function work even without any event associated with [Bindable] tag.

Example:

<mx:Image id="a" source="{getImage(1)}" useHandCursor="true" buttonMode="true" width="10" height="10" click="finalize(event)" autoLoad="true"/>

[Bindable] private var _ratingSelected:int;

[Bindable]
private function getImage(value:int):String
  {
if (value <= _ratingSelected)
return 'images/hr/applicants/star_icon.png';
else
return 'images/hr/applicants/star_icon_dis.png';
  }

If I remove the Bindable tag from getImage function here, the image doesnt properly get updated a开发者_C百科t the run time. Please note that _ratingSelected is Bindable variable here. Even though I don't have any event associated with getImage() function, making it Bindable seems to be working just alright. Does it automatically detect changes to changes in _ratingSelected variable (which is bindable) and call the getImage function at run time? Kindly enlighten.

Thanks.


When you don't specify an event name in the Binding tag, it uses the event "propertyChange". This means that every time the framework gets a "propertyChange" event from your document, it'll try to update the image source by calling getImage again.

Now when the value of _ratingSelected is updated, a "propertyChange" event is dispatched internally, which then causes the image to be updated.

Note that this has nothing to do with whether getImage actually uses _ratingSelected to generate its return value. The only connection between getImage and _ratingSelected from the data binding framework's point of view is the "propertyChange" event which they both claim to dispatch when their respective values have changed (even though getImage never actually dispatches it).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号