0

ボタンが入ったHBoxがいくつかあります。プログラムで特定のボタンを非表示にします。ある時点で、すべてのボタンが非表示になります。すべてのボタンが非表示になっていることを確認するにはどうすればよいですか?そうするための最も簡単な方法は何ですか?

各ボタンの可視性は、他のボタンとは独立して決定されます。

<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>

ありがとうございました。

-ラクシュミディ

4

2 に答える 2

2

最も簡単な方法は必ずしも最良の方法ではありませんが、このようなものが機能するはずです...

public function areAllButtonsInvisible() : Boolean {
    for ( var i : int = 1; i < 7; i++ ) {
        if ( ( this["button"+i] as UIComponent ).visible {
            return false;
        }
    }
    return true;
}
于 2010-10-06T17:52:13.650 に答える
1

上記のGregorからの回答は、コンポーネント内のすべてのボタンで機能しますが、特定のHBox内のボタンを確認するだけの場合は、次のようにHBoxコンポーネントの子配列で「some」関数を使用できます。

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
    <![CDATA[
        import mx.core.UIComponent;

        private function clickHandler(event:MouseEvent):void{
            (event.target as UIComponent).visible = false;
            buttonsVis.text = box.getChildren().some(isVisible).toString();
        }

        private function isVisible(item:*, index:int, array:Array):Boolean{
            return (item as UIComponent).visible;
        }

    ]]>
</mx:Script>
<mx:HBox id="box">
    <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:Label text="Buttons are Visible: "/><mx:Label id="buttonsVis" text="true"/>

于 2010-10-06T18:13:18.590 に答える