一个RadioButton运用的例子,包含对标签的空值验证
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
verticalAlign="middle"
backgroundColor="white" xmlns:ns1="*">
<mx:Script>
<![CDATA[
private var sexChang:String;
import mx.controls.Alert;
private function rb_change(evt:Event):void {
var rb:RadioButton = evt.currentTarget as RadioButton;
sexChang= rb.label;
}
private function kk():void{
textInput.text=sexChang;
}
]]>
</mx:Script>
<mx:Validator id="sexV" source="{sexRBG}" property="selectedValue" requiredFieldError="必须选择性别!" trigger="{btnRegister}" triggerEvent="click" listener="{maleRB}" />
<mx:FormItem label="性 别:" direction="horizontal" width="177" x="270" y="326">
<mx:RadioButtonGroup id="sexRBG"/>
<mx:RadioButton x="10" id="maleRB" groupName="sexRBG" label="男" value="1" change="rb_change(event)"/>
<mx:RadioButton id="femaleRB" groupName="sexRBG" label="女" value="0" change="rb_change(event)"/>
</mx:FormItem>
<mx:Button id="btnRegister" fontWeight="bold" click="kk()" x="294" y="373" width="88" height="45" label="选择性别" fontSize="13"/>
<mx:TextInput x="270" y="266" id="textInput"/>
</mx:Application>