所在的包是:import fl.controls.*;
类:public class RadioButton
使用RadioButton组件可以强制用户只能从一组选项中选择一项。该组件不需用于有两个RadioButton组件实例的组,在任何给定的情况下,都只有一个组成员被选中,选择组中的一个单选按钮将取消选择组内当前选定的单选按钮, 您可以设置 groupName
参数,以指示单选按钮属于哪个组。 当用户单击或使用 Tab 切换到 RadioButton 组件组时,只有选定的单选按钮会获得焦点。
//可以启用或禁用单选按钮。 禁用的单选按钮不接收鼠标或键盘输入。
例如:
package { import flash.text.TextFieldAutoSize; import flash.display.Sprite; import flash.events.MouseEvent; import fl.controls.RadioButton; import fl.controls.RadioButtonGroup; import fl.controls.Label; import fl.controls.Button; public class RadioButtonExample extends Sprite { private var j:uint; private var padding:uint = 10; private var currHeight:uint = 0; private var verticalSpacing:uint = 30; private var rbg:RadioButtonGroup; private var questionLabel:Label; private var answerLabel:Label; private var question:String = "What day is known internationally as Speak Like A Pirate Day?" private var answers:Array = [ "August 12", "March 4", "September 19", "June 22" ]; public function RadioButtonExample() { setupQuiz(); } private function setupQuiz():void { setupQuestionLabel(); setupRadioButtons(); setupButton(); setupAnswerLabel(); } private function setupQuestionLabel():void { questionLabel = new Label(); questionLabel.text = question; questionLabel.autoSize = TextFieldAutoSize.LEFT; questionLabel.move(padding,padding + currHeight); currHeight += verticalSpacing; addChild(questionLabel); } private function setupAnswerLabel():void { answerLabel = new Label(); answerLabel.autoSize = TextFieldAutoSize.LEFT; answerLabel.move(padding + 120,padding + currHeight); addChild(answerLabel); } private function setupRadioButtons():void { rbg = new RadioButtonGroup("question1"); createRadioButton(answers[0], rbg); createRadioButton(answers[1], rbg); createRadioButton(answers[2], rbg); createRadioButton(answers[3], rbg); } private function setupButton():void { var b:Button = new Button(); b.move(padding,padding + currHeight); b.label = "Check Answer"; b.addEventListener(MouseEvent.CLICK,checkAnswer); addChild(b); } private function createRadioButton(rbLabel:String,rbg:RadioButtonGroup):void { var rb:RadioButton = new RadioButton(); rb.group = rbg; rb.label = rbLabel; rb.move(padding, padding + currHeight); addChild(rb); currHeight += verticalSpacing; } private function checkAnswer(e:MouseEvent):void { if(!rbg.selection.label) answerLabel.text = "Select an answer."; else { var resultStr:String = rbg.selection.label == answers[2] ? "Correct" : "Incorrect"; answerLabel.text = resultStr; } } } }
公共属性有:autoRepeat:Boolean---单选按钮按定义始终是不可自动重复的,因此,autoRepeat属性在构造函数中被设置为false并且不能更改
group:RadioButtonGroup---此RadioButton所属的RadioButtonGroup对象
groupName:String---单选按钮的实例或组的组名
selected:Boolean---指示单选按钮当前处于选中状态(true)还是取消选中状态(false)。
toggle:Boolean---单选按钮是一种切换按钮;其toggle属性在构造函数中设置为true,并且不能更改。
value:Object---与单选按钮关联的用户定义值。
公共方法有:RadioButton()---创建新的RadioButton组件实例。
drawFocus(focused:Boolean):void---在此组件实例周围显示或隐藏焦点指示符。
getStyleDefinition():Object---【静态】检索当前组件的默认的样式映射。
事件有:change---在单选按钮实例的selected属性发生变化时调度。
click---当用户使用鼠标或空格键单击单选按钮时调度。
样式:
disabledIcon---类型:Class 类的名称,该类用作未禁用按钮时的图标,默认值为RadioButton_disabledIcon.
downIcon---类型同上,....,该类用作未选择按钮而按下了鼠标按键时的图标默认值为RadioButton_downIcon。
icon---....,....,该类用作未选择切换按钮且鼠标光标不在按钮上方时的图标。 默认值为 null
.
overIcon----....,....,该类用作当未选择按钮且鼠标光标在组件上方时的图标。 默认值为RadioButton_overIcon.
5
.