Flex中如何通过设置RadioButtonGroup类的selection属性用ActionScript清除当前选中RadioButton的例子
By Minidxer | February 7, 2009
接下来的例子演示了Flex中如何通过设置RadioButtonGroup类的selection属性,用ActionScript清除当前选中RadioButton。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <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 reset():void {
- answers.selection = null;
- }
- private function check():void {
- if (answers.selectedValue) {
- Alert.show(answers.selectedValue.toString());
- } else {
- Alert.show("unselected");
- }
- }
- ]]>
- </mx:Script>
- <mx:RadioButtonGroup id="answers" />
- <mx:Form backgroundColor="red">
- <mx:FormItem>
- <mx:Text id="question"
- text="Question..." />
- </mx:FormItem>
- <mx:FormItem>
- <mx:RadioButton id="answer1"
- group="{answers}"
- label="Answer 1" />
- </mx:FormItem>
- <mx:FormItem>
- <mx:RadioButton id="answer2"
- group="{answers}"
- label="Answer 2" />
- </mx:FormItem>
- <mx:FormItem>
- <mx:RadioButton id="answer3"
- group="{answers}"
- label="Answer 3" />
- </mx:FormItem>
- <mx:FormItem>
- <mx:RadioButton id="answer4"
- group="{answers}"
- label="Answer 4" />
- </mx:FormItem>
- <mx:FormItem>
- <mx:RadioButton id="answer5"
- group="{answers}"
- label="Answer 5" />
- </mx:FormItem>
- <mx:FormItem direction="horizontal">
- <mx:Button label="Check" click="check();" />
- <mx:Button label="Reset" click="reset();" />
- </mx:FormItem>
- </mx:Form>
- </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子
Topics:
RadioButton |
No Comments » |
854 views
Tags: RadioButton, RadioButtonGroup, selectedValue, selection