<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
private function resetForm():void
{
var instanceInfo:XML=describeType(this);//通过反射机制取出当前MXML中的信息
var properties:XMLList =instanceInfo..accessor.(@type=="mx.controls::TextInput")
for each(var propertyInfo:XML in properties){
var propertyName:String
=propertyInfo.@name;
//此处取出的为control的id
TextInput(this[propertyName]).text="";
}
}
]]>
</mx:Script>
<mx:Panel title="用户注册信息" width="359" height="303" x="24.5" y="37" fontSize="12">
<mx:Form id="form" width="100%" height="100%" horizontalGap="0">
<mx:FormHeading label="用户资料" width="100%"/>
<mx:FormItem label="用户名:" width="100%" required="true">
<mx:TextInput width="100%" id="user_txt"/>
</mx:FormItem>
<mx:FormItem label="密码:" width="100%" required="true">
<mx:TextInput width="100%" displayAsPassword="true" id="pass_txt"/>
</mx:FormItem>
<mx:FormItem label="性别:" width="100%" direction="horizontal">
<mx:RadioButton groupName="isMale" label="男" /> <mx:RadioButton groupName="isMale" label="女" />
</mx:FormItem>
<mx:FormItem label="邮箱:" width="100%">
<mx:TextInput width="100%" id="email_txt"/>
</mx:FormItem>
<mx:FormItem label="电话:" width="100%">
<mx:TextInput width="100%" id="phone_txt"/>
</mx:FormItem>
<mx:FormItem label="出生年月:" width="100%">
<mx:TextInput width="100%" id="birth_txt"/>
</mx:FormItem>
</mx:Form>
<mx:ControlBar height="32" paddingBottom="0" paddingTop="0" horizontalAlign="center">
<mx:Button id="btnSubmit" label="确定"/>
<mx:Button id="btnReset" label="重置" click="resetForm();"/><!--flex里没有重置按钮-->
</mx:ControlBar>
</mx:Panel>
<mx:StringValidator source="{user_txt}" property="text" minLength="6" maxLength="12" tooShortError="用户名太短了" trigger="{btnSubmit}" triggerEvent="click"/>
<mx:StringValidator source="{pass_txt}" property="text" minLength="6" maxLength="12" trigger="{btnSubmit}" triggerEvent="click"/>
<mx:PhoneNumberValidator source="{phone_txt}" property="text" trigger="{btnSubmit}" triggerEvent="click"/>
<mx:DateValidator source="{birth_txt}" property="text" trigger="{btnSubmit}" triggerEvent="click"/>
<mx:EmailValidator source="{email_txt}" property="text" trigger="{btnSubmit}" triggerEvent="click"/>
</mx:Application>
转载于:https://www.cnblogs.com/yuji/archive/2009/03/24/1420506.html