Search code examples
apache-flexbuttoninvisible

Flex : Detecting When Buttons are Invisible


I've got a few HBoxes with buttons in them. I programmatically make certain buttons invisible. At a certain point, all of the buttons should be invisible. How can I tell when all of the buttons are invisible? What's the easiest way of doing so?

Each button's visibility is determined independently of the other buttons.

<mx:HBox>
    <mx:Button id="button1" 
    click="clickHandler(event);" 
    toggle="true"
    visible=true/>

    <mx:Button id="button2" 
    click="clickHandler(event);" 
    toggle="true"
    visible=false/>

    <mx:Button id="button3" 
    click="clickHandler(event);" 
    toggle="true"
    visible=true/>
</mx:HBox>

<mx:HBox>
    <mx:Button id="button4" 
    click="clickHandler(event);" 
    toggle="true"
    visible=false/>

    <mx:Button id="button5" 
    click="clickHandler(event);" 
    toggle="true"
    visible=true/>

    <mx:Button id="button6" 
    click="clickHandler(event);" 
    toggle="true"
    visible=false/>
</mx:HBox>

Thank you.

-Laxmidi


Solution

  • Easiest way is not necessarily the best way but something like this should work...

    public function areAllButtonsInvisible() : Boolean {
        for ( var i : int = 1; i < 7; i++ ) {
            if ( ( this["button"+i] as UIComponent ).visible {
                return false;
            }
        }
        return true;
    }