RadioButtonとRadioButtonGroup
ラジオボタンの感覚からはRadioButtonGroupが便利。
RadioButton
ボタン1つ1つにイベントハンドラーが必要になるが、細かい動きが出来る。
<mx:Script> <![CDATA[ import flash.events.Event; private function handleAmEx(event:Event):void { ... } private function handleMC(event:Event):void { ... } private function handleVisa(event:Event):void { ... } ]]> </mx:Script> <mx:RadioButton groupName="cardtype" id="americanExpress" label="American Express" width="150" click="handleAmEx(event);"/> <mx:RadioButton groupName="cardtype" id="masterCard" label="MasterCard" width="150" click="handleMC(event);"/> <mx:RadioButton groupName="cardtype" id="visa" label="Visa" width="150" click="handleVisa(event);"/> http://livedocs.adobe.com/flex/2_jp/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000538.html
RadioButtonGroup
mx:RadioButtonGroupのidからボタンの値が受け取れる。
ex:)RadioButtonGroupNAME.selectedValue.toString()
<?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.ItemClickEvent; private function handleCard(evtObj:ItemClickEvent):void { if (evtObj.currentTarget.selectedValue == "AmEx") { Alert.show("You selected American Express") } else { if (evtObj.currentTarget.selectedValue == "MC") { Alert.show("You selected Master Card") } else { Alert.show("You selected Visa") } } } ]]> </mx:Script> <mx:RadioButtonGroup id="cardtype" itemClick="handleCard(event)"/> <mx:RadioButton groupName="cardtype" id="americanExpress" value="AmEx" label="American Express" width="150"/> <mx:RadioButton groupName="cardtype" id="masterCard" value="MC" label="MasterCard" width="150"/> <mx:RadioButton groupName="cardtype" id="visa" value="Visa" label="Visa" width="150"/> </mx:Application> http://livedocs.adobe.com/flex/2_jp/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000538.html