Flex ChangeWatcher bind to a negative condition
I have a bindable getter in a component which informs me when a [hidden] timer is running. I also have a context menu which, if this timer is running, should disable one of the menu items. Is it po开发者_Go百科ssible to create a ChangeWatcher which watches for the negative condition of a bindable property/getter and changes the enabled
property of the menu item?
Here are the basic methods I'm trying to bind together:
Class A:
[Bindable]
public function get isPlaying():Boolean {
return (_timer != null) ? _timer.running : false;
}
Class B:
private var _playingWatcher:ChangeWatcher;
public function createContextMenu():void {
//...blah blah, creating context menu
var newItem:ContextMenuItem = new ContextMenuItem();
_playingWatcher = BindingUtils.bindProperty(newItem, "enabled", _classA, "isPlaying");
}
In the code above, I have the inverse case: when isPlaying() is true, the menu item is enabled; I want it to only be enabled when the condition is false.
I could create a second getter (there are other bindings which rely on the current getter) to return the inverse condition, but that sounds ugly to me:
[Bindable]
public function get isNotPlaying():Boolean {
return !isPlaying;
}
Is this possible, or is there another approach I'm completely missing?
Could use bind Setter on binding utils but your approach seems valid otherwise bind property is blind to the types of properties it's mapping so it has no negative condition parameter.
I would extend ContextMenuItem and create a custom property on it that you can use to set the enabled or not of the underlying ContextMenuItem
精彩评论