1、
<?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.events.ItemClickEvent;
private function radioGroup_itemClick(evt:ItemClickEvent):void {
var now:String = new Date().toTimeString();
lbl.text = evt.label + " (" + now + ")";
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<mx:Label id="lbl" fontWeight="bold" />
</mx:ApplicationControlBar>
<mx:RadioButtonGroup id="radioGroup"
itemClick="radioGroup_itemClick(event);" />
<mx:VBox>
<mx:RadioButton id="radioButton1"
label="Red"
group="{radioGroup}" />
<mx:RadioButton id="radioButton2"
label="Orange"
group="{radioGroup}" />
<mx:RadioButton id="radioButton3"
label="Yellow"
group="{radioGroup}" />
<mx:RadioButton id="radioButton4"
label="Green"
group="{radioGroup}" />
<mx:RadioButton id="radioButton5"
label="Blue"
group="{radioGroup}" />
</mx:VBox>
</mx:Application>
2、
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
viewSourceURL="srcview/index.html">
<fx:Script>
<![CDATA[
protected function scoreClickHandler(event:MouseEvent):void
{
var score:Number = 0.0;
if (group1.selectedValue=="True")
score=33.34;
if (group2.selectedValue=="South Africa")
score=score+33.34;
if (group3.selectedValue=="False")
score=score+33.34;
scoreText.text = "You scored " + numberFormatter.format(score).toString()+"%";
}
]]>
</fx:Script>
<fx:Declarations>
<s:RadioButtonGroup id="group1"/>
<s:RadioButtonGroup id="group2"/>
<s:RadioButtonGroup id="group3"/>
<mx:NumberFormatter id="numberFormatter"
precision="0"
rounding="nearest"/>
</fx:Declarations>
<fx:Style>
@namespace "library://ns.adobe.com/flex/spark";
RadioButton{
baseColor: #FFFFFF;
}
</fx:Style>
<!-- Note: A custom panel skin is used for the Tour de Flex samples and is included in the
source tabs for each sample. -->
<s:Panel title="RadioButton Sample"
width="100%" height="100%"
skinClass="skins.TDFPanelSkin">
<s:HGroup horizontalCenter="0" top="10">
<s:VGroup>
<s:Label text="1) The sky is blue:"/>
<s:RadioButton id="trueRadioBtn" label="True" groupName="group1"/>
<s:RadioButton id="falseRadioBtn" label="False" groupName="group1"/>
</s:VGroup>
<s:VGroup paddingLeft="20">
<s:Label text="2) Which of the following is not a continent?"/>
<s:RadioButton id="multiRadioBtnA" label="North America" groupName="group2"/>
<s:RadioButton id="multiRadioBtnB" label="Europe" groupName="group2"/>
<s:RadioButton id="multiRadioBtnC" label="Asia" groupName="group2"/>
<s:RadioButton id="multiRadioBtnD" label="South Africa" groupName="group2"/>
</s:VGroup>
<s:VGroup paddingLeft="20">
<s:Label text="3) Tallahasee is the capital of Alabama:"/>
<s:RadioButton id="trueRadioBtn3" label="True" groupName="group3" />
<s:RadioButton id="falseRadioBtn3" label="False" groupName="group3"/>
</s:VGroup>
<s:VGroup horizontalAlign="contentJustify">
<s:Button id="scoreBtn" label="Score Me!" click="scoreClickHandler(event)"/>
<s:Label id="scoreText"/>
</s:VGroup>
</s:HGroup>
<s:Label bottom="20" left="5" width="100%" verticalAlign="justify" color="#323232"
text="The RadioButton control is a single choice in a set of mutually
exclusive choices. A RadioButton group is composed of two or more RadioButton controls with
the same group name. Only one member of the group can be selected at any given time." />
</s:Panel>
</s:Application>