`
hacker47
  • 浏览: 336606 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

FLEX入门篇——FLEX的校验组件及HTTPService交互方式

阅读更多

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
	<![CDATA[
		import mx.controls.Alert;
		import mx.events.ValidationResultEvent;
		private function Vemail():void{
			if(emailV.validate().type==ValidationResultEvent.VALID){
				Alert.show("邮箱验证通过","校验提示",Alert.YES|Alert.NO);
			}else if(emailV.validate().type==ValidationResultEvent.INVALID){
				Alert.show("邮箱错误");
			}
		}
	]]>
</mx:Script>
<mx:Model id="contact">
	<info>
		<phone>{phone.text}</phone>
		<name>{userName.text}</name>
		<email>{email.text}</email>
	</info>
</mx:Model>
  <!--
    使用JAVA的话我们在后台,比如servlet中就可以这样得到HttpService传递的值request.getParameter("phone");
request.getParameter("name");....当然这是一种比较原始的传值方式了,在数据量较小或参数较少时无所谓,如果参数很多,或数据量很大的情况下,我个人比较喜欢使用remotingObject方式来处理,将所有参数封闭成一个实体的属性,然后用对象的方式来处理  -->
<mx:HTTPService id="myService" resultFormat="e4x" url="http://localhost:8080/reg" useProxy="false">
</mx:HTTPService>
<mx:StringValidator id="userNameV" source="{userName}"  minLength="6" maxLength="30" property="text"/>
<mx:PhoneNumberValidator id="phoneV" source="{phone}" property="text"/>
<mx:EmailValidator id="emailV" source="{email}" property="text"
		invalidCharError="非法字符"
		invalidDomainError="非法域"
		invalidIPDomainError="非法IP域"
		missingAtSignError="缺少@符号"
		missingPeriodInDomainError="缺少域后缀"
		missingUsernameError="缺少用户名"/>
		<!-- 在默认情况下,是在控件失去焦点时,触发的机校验事件,我们自己也可以通过trigger指定触发,
			还可以通过校验组件ID.validate()函数来触发 -->
	<mx:Panel
		title="My Application" 
		paddingTop="10"
		paddingBottom="10"
		paddingLeft="10"
		paddingRight="10" >
	<mx:VBox width="600">
	<mx:TextInput id="userName"/>
	<mx:HBox width="600">
	<mx:TextInput id="phone"/>
	<mx:Label text="{phone.errorString}"/>
	</mx:HBox>
	<mx:HBox width="600">
	<mx:TextInput id="email"/>
	<mx:LinkButton id="linkBtn" label="立即校验" click="Vemail();"/>	
	</mx:HBox>
	<mx:Button id="sendBtn" label="sendInfo" click="myService.send(contact);"/>
	<!--
		其实在这里还有一种写法,就是不用显式地给linkButton加上事件和处理方法可以直接在校验组件里指定
		<mx:PhoneNumberValidator id="phoneV" source="{phone}" property="text" trigger="{linkBtn}" triggerEvent="校验方法比如:emailV()"/>
	-->
	</mx:VBox>
</mx:Panel>
</mx:Application>


分享到:
评论
2 楼 leisure 2009-06-25  
问个问题:
采用
   <mx:Model id="contact">  
    <info>  
        <a.phone>{phone.text}</a.phone>  
        <a.name>{userName.text}</a.name>  
        <a.email>{email.text}</a.email>  
    </info>  
</mx:Model>  



行不行,用struts2可以自动封装成对象a
1 楼 lydawen 2009-03-02  
总体感觉flex就像是html+js一样。所以学起来也比较简单。不过最终我的目的是flex,esb,ejb,jpa... 项目要求技术大转型啊

相关推荐

Global site tag (gtag.js) - Google Analytics