代码
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
fontSize="12" horizontalAlign="center" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function init():void{
generate.text=generateCheckCode();
}
//登录验证
private function loginHandler():void{
if(user.text==""||pass.text==""){
Alert.okLabel="确定";
Alert.show("用户名 或 密码 为空","提示");
}else{
if(user.text=="jianbao"&&pass.text=="jianbao"
&&identify.text.toLowerCase()==generate.text.toLowerCase()){
Alert.okLabel="确定";
Alert.show("登录成功","提示");
currentState="hollow";
}else{
if(identify.text.toLowerCase()!=generate.text.toLowerCase()){
Alert.okLabel="确定";
Alert.show("验证码输入错误","提示");
generate.text=generateCheckCode();
}else{
Alert.okLabel="确定";
Alert.show("用户名 或 密码 错误","提示");
}
}
}
}
//清除
private function clearHandler():void{
user.text=pass.text="";
}
//产生验证吗
private function generateCheckCode():String{
//init
var num:Number;
var code:String;
var checkCode:String="";
for(var i:int=0;i<5;i++){
num=Math.round(Math.random()*100000);
if(num%2==0){
code=String.fromCharCode(48+(num%10));
}else{
code=String.fromCharCode(65+(num%26));
}
checkCode +=code;
}
return checkCode;
}
]]>
</mx:Script>
<mx:Panel id="panel" x="143" y="115" width="350" height="229" layout="absolute" title="login">
<mx:Button id="btnLogin" x="73" y="141" label="登录" click="loginHandler()"/>
<mx:Button id="btnClear" x="167" y="141" label="清除" click="clearHandler()"/>
<mx:Label x="41" y="31" text="用户名"/>
<mx:Label x="44" y="64" text="密 码"/>
<mx:TextInput id="user" x="81" y="31"/>
<mx:TextInput id="pass" x="81" y="62" displayAsPassword="true"/>
<mx:Text x="40" y="100" text="验证码"/>
<mx:TextInput x="81" y="98" width="68" id="identify"/>
<mx:Label x="156" y="100" width="48" id="generate"/>
<mx:Label x="209" y="100" text="看不清楚 换个~~" click="generate.text=generateCheckCode()" />
</mx:Panel>
<mx:states>
<mx:State name="hollow">
<mx:RemoveChild target="{panel}"/>
<mx:AddChild position="lastChild">
<mx:Label text="hollow marshane" x="0" y="200" fontSize="200" color="red"/>
</mx:AddChild>
</mx:State>
</mx:states>
</mx:Application>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
fontSize="12" horizontalAlign="center" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function init():void{
generate.text=generateCheckCode();
}
//登录验证
private function loginHandler():void{
if(user.text==""||pass.text==""){
Alert.okLabel="确定";
Alert.show("用户名 或 密码 为空","提示");
}else{
if(user.text=="jianbao"&&pass.text=="jianbao"
&&identify.text.toLowerCase()==generate.text.toLowerCase()){
Alert.okLabel="确定";
Alert.show("登录成功","提示");
currentState="hollow";
}else{
if(identify.text.toLowerCase()!=generate.text.toLowerCase()){
Alert.okLabel="确定";
Alert.show("验证码输入错误","提示");
generate.text=generateCheckCode();
}else{
Alert.okLabel="确定";
Alert.show("用户名 或 密码 错误","提示");
}
}
}
}
//清除
private function clearHandler():void{
user.text=pass.text="";
}
//产生验证吗
private function generateCheckCode():String{
//init
var num:Number;
var code:String;
var checkCode:String="";
for(var i:int=0;i<5;i++){
num=Math.round(Math.random()*100000);
if(num%2==0){
code=String.fromCharCode(48+(num%10));
}else{
code=String.fromCharCode(65+(num%26));
}
checkCode +=code;
}
return checkCode;
}
]]>
</mx:Script>
<mx:Panel id="panel" x="143" y="115" width="350" height="229" layout="absolute" title="login">
<mx:Button id="btnLogin" x="73" y="141" label="登录" click="loginHandler()"/>
<mx:Button id="btnClear" x="167" y="141" label="清除" click="clearHandler()"/>
<mx:Label x="41" y="31" text="用户名"/>
<mx:Label x="44" y="64" text="密 码"/>
<mx:TextInput id="user" x="81" y="31"/>
<mx:TextInput id="pass" x="81" y="62" displayAsPassword="true"/>
<mx:Text x="40" y="100" text="验证码"/>
<mx:TextInput x="81" y="98" width="68" id="identify"/>
<mx:Label x="156" y="100" width="48" id="generate"/>
<mx:Label x="209" y="100" text="看不清楚 换个~~" click="generate.text=generateCheckCode()" />
</mx:Panel>
<mx:states>
<mx:State name="hollow">
<mx:RemoveChild target="{panel}"/>
<mx:AddChild position="lastChild">
<mx:Label text="hollow marshane" x="0" y="200" fontSize="200" color="red"/>
</mx:AddChild>
</mx:State>
</mx:states>
</mx:Application>
效果图: