小小菜鸟的web菜园子

web开发学习。好记性不如烂笔头。每天进步一点点!

导航

循环访问RadioButtonGroup中的各个子项的值.

numRadioButtons 属性and getRadioButtonAt() 方法.
示例:


代码:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/06/20/looping-over-radiobutton-controls-in-a-radiobuttongroup-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout
="vertical"
        verticalAlign
="middle"
        backgroundColor
="white">

    
<mx:Script>
        
<![CDATA[
            import mx.controls.Alert;

            private function showAlert():void {
                var arr:Array = [];
                var rb:RadioButton;
                var idx:int;
                var len:int = radioGroup.numRadioButtons;

                for (idx=0; idx<len; idx++) {
                    rb = radioGroup.getRadioButtonAt(idx);
                    arr.push("index:" + idx + ", label:" + rb.label);
                }
                Alert.show(arr.join("\n"), "getRadioButtonAt():");
            }
        
]]>
    
</mx:Script>

    
<mx:ApplicationControlBar dock="true">
        
<mx:Button label="Click me" click="showAlert();" />
    
</mx:ApplicationControlBar>

    
<mx:RadioButtonGroup id="radioGroup" />

    
<mx:VBox>
        
<mx:RadioButton id="radioButton1" label="One" />
        
<mx:RadioButton id="radioButton2" label="Two" />
        
<mx:RadioButton id="radioButton3" label="Three" />
        
<mx:RadioButton id="radioButton4" label="Four" />
        
<mx:RadioButton id="radioButton5" label="Five" />
    
</mx:VBox>

</mx:Application>

posted on 2008-07-05 11:44  『小小菜鸟』  阅读(893)  评论(0编辑  收藏  举报