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

flex 随机产生颜色

    博客分类:
  • flex
 
阅读更多
servlet 实现注册功能的前台代码

<?xml version="1.0" encoding="UTF-8"?>
<s:Group
 xmlns:fx="http://ns.adobe.com/mxml/2009"
 xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/halo" 
creationComplete="group1_creationCompleteHandler(event)"


 width="529" height="302" alpha="0.8" > 
<s:layout> 
<s:VerticalLayout horizontalAlign="center" useVirtualLayout="true"> 
</s:VerticalLayout>
 </s:layout>
 <s:Panel width="100%" height="100%">
 <s:VGroup width="100%" height="100%" >
 <s:Group width="100%" height="20%">
 <s:layout>
 <s:HorizontalLayout useVirtualLayout="true" verticalAlign="middle" > 
</s:HorizontalLayout>
 </s:layout>
 <mx:Label text="用户名:" width="100" textAlign="right"/>
 <s:TextInput width="50%" id="userNameTxt"/>
 </s:Group>

 <s:Group width="100%" height="20%">
 <s:layout>
 <s:HorizontalLayout useVirtualLayout="true" verticalAlign="middle">

 </s:HorizontalLayout>
 </s:layout>
 <mx:Label text="密码:" width="100" textAlign="right"/>
 <s:TextInput width="50%" displayAsPassword="true" id="passWordTxt" />
 </s:Group>

 <s:Group width="100%" height="20%">
 <s:layout>
 <s:HorizontalLayout useVirtualLayout="true" verticalAlign="middle">

 </s:HorizontalLayout>
 </s:layout>
 <mx:Label text="性别:" width="100" textAlign="right"/>
 <mx:ComboBox selectedIndex="-1" prompt="请选择性别" labelField="name" width="10%" dataProvider="{dp}" id="sex"> 
</mx:ComboBox> 
</s:Group>

 <s:Group width="100%" height="20%" >
 <s:layout>
 <s:HorizontalLayout useVirtualLayout="true" verticalAlign="middle">
 </s:HorizontalLayout>
 </s:layout>
 <s:Button label="确定" id="regist_queding" click="regist_queding_clickHandler(event)"/>
 <s:Button label="关闭" id="regist_colse" click="regist_colse_clickHandler(event)"/> 
</s:Group>
 </s:VGroup>

 </s:Panel>


 <fx:Script>
 <![CDATA[ 
import mx.validators.Validator;
 import mx.rpc.events.ResultEvent;
 import mx.collections.ArrayCollection;
 import mx.managers.PopUpManager;
 import mx.controls.Alert;
 import mx.events.FlexEvent; 
[Bindable]
 public var bgColor:uint;
 [Bindable]
 private var dp:ArrayCollection=new ArrayCollection([{name:'男'},{name:'女'}]);


protected function image1_clickHandler(event:MouseEvent):void
 {
 PopUpManager.removePopUp(this);
 }
 protected function regist_queding_clickHandler(event:MouseEvent):void
 {
 if(Validator.validateAll(validatorArray).length==0){ 
var par:URLVariables = new URLVariables();
 par.userName=userNameTxt.text;
 par.passWord=passWordTxt.text;
 par.sex=sex.selectedLabel;
 regist.send(par);

 }else{
 userNameTxt.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OVER));
 passWordTxt.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OVER));
 sex.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OVER)); 
}
 }
 protected function regist_colse_clickHandler(event:MouseEvent):void
 {
 PopUpManager.removePopUp(this);
 }
 protected function regist_resultHandler(event:ResultEvent):void
 {
 var mes:String = event.message.body.toString(); 

if(mes=="true"){
 Alert.show("注册成功");
 // PopUpManager.removePopUp(this);
 }else{
 Alert.show("注册失败");
 }

 }
 

protected function group1_creationCompleteHandler(event:FlexEvent):void
 {
 bgColor=Math.random()*0xFFFFFF;
 }
 
]]>
 </fx:Script>
 <fx:Declarations>
 <s:HTTPService id="regist" url="../servlet/UserServlet?action=regist" result="regist_resultHandler(event)"> 
</s:HTTPService>
 <fx:Array id="validatorArray">
 <mx:StringValidator source="{userNameTxt}" property="text" tooShortError="最少要5个字符" requiredFieldError="不能为空"
tooLongError="最长不能超长20个字符" minLength="5" maxLength="20"/>
 <mx:StringValidator source="{passWordTxt}" property="text" tooShortError="最少要6个字符" requiredFieldError="不能为空" 
tooLongError="最长不能超长20个字符" minLength="6" maxLength="20"/>
 <mx:NumberValidator source="{sex}" lowerThanMinError="请选择性别" property="selectedIndex" minValue="0"/> 
</fx:Array>
 </fx:Declarations>

</s:Group>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics