<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="vertical" creationComplete="initApp()">
<mx:states>
<!--新建“index”State-->
<mx:State name="index">
<!--移除“登錄框”-->
<mx:RemoveChild target="{panel1}"/>
<!--添加新的組件-->
<mx:AddChild position="lastChild">
<mx:Label x="231" y="174" text="歡迎來到主頁" fontFamily="Georgia" fontSize="20" />
</mx:AddChild>
</mx:State>
</mx:states>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function initApp():void{
lblCheckCode.text=GenerateCheckCode();
}
private function loginHandle():void{
if(txtUsername.text=="" || txtPassword.text==""){
Alert.show("用戶名或者密碼輸入不完整!");
}
if(txtUsername.text=="licui"&& txtPassword.text=="123" && txtCheckCode.text.toLocaleLowerCase()==lblCheckCode.text.toLocaleLowerCase()){
currentState="index";
}else{
if(txtCheckCode.text.toLocaleLowerCase()!=lblCheckCode.text.toLocaleLowerCase()){
Alert.show("驗證碼不正確:");
lblCheckCode.text=GenerateCheckCode();
}else{
Alert.show("用戶名或者密碼輸入不正確!");
}
}
}
private function resetHandle():void{
txtUsername.text="";
txtPassword.text="";
txtCheckCode.text="";
}
private function GenerateCheckCode():String{
var ran:Number;
var number:Number;
var code:String;
var checkcode:String="";
//生成四爲隨機數
for(var i:int=0;i<4;i++){
ran=Math.random();
number=Math.round(ran*1000);
if(number%2==0)
code=String.fromCharCode(48+(number%10));
else
code=String.fromCharCode(65+(number%26));
checkcode+=code;
}
return checkcode;
}
]]>
</mx:Script>
<mx:Panel x="108" y="71" width="349" height="257" layout="absolute" title="用戶登錄" fontFamily="Georgia" fontSize="12" id="panel1">
<!-- "用戶名"標籤 -->
<mx:Label x="41.5" y="33" text="用戶名"/>
<!-- "密碼"標籤 -->
<mx:Label x="42.5" y="81" text="密碼"/>
<!-- "用戶名"輸入框 -->
<mx:TextInput x="94.5" y="33" id="txtUsername"/>
<!-- "密碼"輸入框 -->
<mx:TextInput x="95.5" y="81" id="txtPassword" displayAsPassword="true"/>
<!-- "登錄"按鈕 -->
<mx:Button x="82.5" y="159" label="登錄" id="btnLogin" click="loginHandle()"/>
<!-- "重置"按鈕 -->
<mx:Button x="181.5" y="159" label="重置" id="btnReset" click="resetHandle()"/>
<!-- "校驗碼"標籤 -->
<mx:Label x="165.5" y="125" id="lblCheckCode" width="42.5" color="#377CD0"/>
<mx:LinkButton x="216" y="123" label="看不清楚?" id="linkbtnReGenerate" click="lblCheckCode.text=GenerateCheckCode();" fontFamily="Georgia" fontSize="11"/>
<mx:Label x="39.5" y="123" text="校驗碼"/>
<!-- "校驗碼"輸入框 -->
<mx:TextInput x="96.5" y="121" id="txtCheckCode" width="61" maxChars="4"/>
</mx:Panel>
</mx:Application>
flex登錄界面實例2
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.