<?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" minWidth="955" minHeight="600" creationComplete="init()">
<s:states>
<s:State name="State1"/>
<s:State name="index"/>
</s:states>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
//生成随机码
private function init():void{
var checkCode:String = "";
for(var i:int=0;i<4;i++){
var random:Number = Math.round(Math.random()*10000);
if(random % 2 == 0){//如果是2的倍数则生成数字
checkCode += String.fromCharCode(48 + (random % 10));
}else{//生成字母
checkCode += String.fromCharCode(65 + (random % 26));
}
}
lCheckCode.text = checkCode;
}
private function checkLogin():void{
var name:String = txtName.text;
var passWord:String = txtPassword.text;
var checkCode:String = lCheckCode.text;
if("" != name && "" != passWord && "" != checkCode){
if(checkCode.toLowerCase() != txtCheckCode.text.toLowerCase()){
Alert.show("验证码不正确","提示信息:")
return;
}
this.currentState="index";
}else{
Alert.show("请填写用户名,密码或验证码!","提示信息:");
return;
}
}
private function resetText():void{
this.txtName.text = "";
this.txtPassword.text = "";
this.txtCheckCode.text = "";
}
]]>
</fx:Script>
<s:Panel title="用户登录" width="358" height="239" includeIn="State1">
<s:TextInput x="152" y="19" width="151" id="txtName"/>
<s:TextInput x="152" y="67" width="151" id="txtPassword"/>
<s:Label x="76" y="32" text="姓名:" width="45" height="13"/>
<s:Label x="77" y="67" text="密码:" width="45" height="13"/>
<s:Label x="77" y="111" text="验证码:"/>
<s:TextInput x="154" y="107" width="68" id="txtCheckCode"/>
<s:Label x="230" y="117" text="AAAA" id="lCheckCode" fontStyle="italic" color="#FF0000"/>
<s:Button x="77" y="160" label="登录" click="checkLogin()"/>
<s:Button x="198" y="160" label="重置" click="resetText()"/>
<s:Label x="263" y="118" text="看不清?" click="init()" color="#4997EF"/>
</s:Panel>
<s:Label includeIn="index" x="270" y="130" text="登录成功!" color="#FB0404" fontSize="30"/>
</s:Application>
登录验证
最新推荐文章于 2024-02-21 15:26:03 发布