Tag Archives: RadioButton

RadioButton

CheckBox同様、アンケートフォームなどで良く利用されるRadioButton。他の言語同様にその扱いは同じ
RadioButtonGroupが同グループならグループ内のRadioButtonは選択されたボタンはON,それ以外はOFFとなる

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import fl.controls.RadioButton;
	import fl.controls.RadioButtonGroup;
	import flash.text.*;
 
	public class RadioButtonClass extends Sprite{
		private var _RadioButton:RadioButton;									//ラジオボタン
		private var labelArr:Array = ["YES", "NO"]								//ラベル配列
		private var _RBGroup:RadioButtonGroup = new RadioButtonGroup("JUDGE");	//グループ名
 
		private var resultTXT:TextField;
		public function RadioButtonClass(){
 
			for(var i:int=0; i<labelArr.length; i++){
				_RadioButton = new RadioButton();
				_RadioButton.label = labelArr[i];
				_RadioButton.group = _RBGroup;
				_RadioButton.x = 5;
				_RadioButton.y = (_RadioButton.height + 5) * i;
				_RadioButton.addEventListener(MouseEvent.CLICK, showData);
				addChild(_RadioButton);
				if(i == 0) {
					_RadioButton.selected = true;
				}
			}
 
			resultTXT = new TextField();
			resultTXT.x = 100;
			resultTXT.autoSize = TextFieldAutoSize.LEFT;
			resultTXT.text = labelArr[0];
			addChild(resultTXT);
		}
 
		private function showData(event:Event):void{
			resultTXT.text = "CLICKED LABEL - " + event.currentTarget.label + "\n\n"
							+ "GROUP NAME -   " + event.currentTarget.group.name;
		}
	}
}