Flex ChangeWatcher bind to a negative condition
        Posted  
        
            by 
                bedwyr
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by bedwyr
        
        
        
        Published on 2011-01-07T23:36:30Z
        Indexed on 
            2011/01/07
            23:54 UTC
        
        
        Read the original article
        Hit count: 337
        
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 possible 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?
© Stack Overflow or respective owner