<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="254" height="176"
title="登录" fontSize="13" initialize="initApp();">
<mx:Script>
<![CDATA[
public function initApp():void
{
this.txtUser.setFocus();
}
public function LoginWindow():void
{
if (this.txtUser.text && this.txtPwd.text)
{
if (this.txtUser.text=="ForrestSun" && this.txtPwd.text=="tt")
{
this.lblInfo.visible=false;
this.txtUser.text="";
this.txtPwd.text="";
this.currentState="LogOff";
}
else
{
this.lblInfo.text="用户名或密码错误";
}
}
else
{
this.lblInfo.visible=true;
this.lblInfo.text="用户名或密码不能为空";
}
}
public function LogOffWindow():void
{
this.currentState="";
}
public function LogCancel():void
{
}
]]>
</mx:Script>
<mx:states>
<mx:State name="LogOff">
<mx:SetProperty name="title" value="登录成功"/>
<mx:RemoveChild target="{label0}"/>
<mx:RemoveChild target="{txtUser}"/>
<mx:RemoveChild target="{label3}"/>
<mx:RemoveChild target="{txtPwd}"/>
<mx:RemoveChild target="{cmdLogIn}"/>
<mx:RemoveChild target="{cmdCancel}"/>
<mx:RemoveChild target="{lblInfo}"/>
<mx:AddChild position="lastChild">
<mx:Label text="用户名:" left="24" top="10" fontSize="12" width="62" id="label2"/>
</mx:AddChild>
<mx:AddChild position="lastChild">
<mx:Label text="消息数量:" left="10" top="38" fontSize="12" width="76" id="label1"/>
</mx:AddChild>
<mx:AddChild position="lastChild">
</mx:AddChild>
<mx:AddChild position="lastChild">
<mx:LinkButton label="编辑" fontSize="12" left="10" bottom="10"/>
</mx:AddChild>
<mx:AddChild position="lastChild">
<mx:Label x="76" y="10" text="ForrestSun" fontSize="12"/>
</mx:AddChild>
<mx:AddChild position="lastChild">
<mx:Label x="76" y="38" text="3" fontSize="12"/>
</mx:AddChild>
<mx:SetProperty name="width" value="254"/>
<mx:SetProperty name="height" value="176"/>
<mx:AddChild position="lastChild">
<mx:Button label="退出" enabled="true" right="10" width="54" top="100" buttonDown="LogOffWindow();"/>
</mx:AddChild>
</mx:State>
</mx:states>
<mx:Label text="用户名:" left="6" top="16" fontSize="12" width="62" id="label0"/>
<mx:Label text="密码:" left="20" top="45" fontSize="12" width="52" id="label3"/>
<mx:TextInput y="12" left="56" right="10" id="txtUser"/>
<mx:TextInput y="45" displayAsPassword="true" left="56" right="10" id="txtPwd"/>
<mx:Button label="登录" width="55" fontSize="12" id="cmdLogIn" click="LoginWindow();" right="73" top="79" height="22"/>
<mx:Button label="取消" width="55" fontSize="12" id="cmdCancel" right="10" top="79" height="22"/>
<mx:Label color="#ff0000" fontSize="12" id="lblInfo" bottom="4" left="10" right="10"/>
</mx:Panel>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="254" height="176"
title="登录" fontSize="13" initialize="initApp();">
<mx:Script>
<![CDATA[
public function initApp():void
{
this.txtUser.setFocus();
}
public function LoginWindow():void
{
if (this.txtUser.text && this.txtPwd.text)
{
if (this.txtUser.text=="ForrestSun" && this.txtPwd.text=="tt")
{
this.lblInfo.visible=false;
this.txtUser.text="";
this.txtPwd.text="";
this.currentState="LogOff";
}
else
{
this.lblInfo.text="用户名或密码错误";
}
}
else
{
this.lblInfo.visible=true;
this.lblInfo.text="用户名或密码不能为空";
}
}
public function LogOffWindow():void
{
this.currentState="";
}
public function LogCancel():void
{
}
]]>
</mx:Script>
<mx:states>
<mx:State name="LogOff">
<mx:SetProperty name="title" value="登录成功"/>
<mx:RemoveChild target="{label0}"/>
<mx:RemoveChild target="{txtUser}"/>
<mx:RemoveChild target="{label3}"/>
<mx:RemoveChild target="{txtPwd}"/>
<mx:RemoveChild target="{cmdLogIn}"/>
<mx:RemoveChild target="{cmdCancel}"/>
<mx:RemoveChild target="{lblInfo}"/>
<mx:AddChild position="lastChild">
<mx:Label text="用户名:" left="24" top="10" fontSize="12" width="62" id="label2"/>
</mx:AddChild>
<mx:AddChild position="lastChild">
<mx:Label text="消息数量:" left="10" top="38" fontSize="12" width="76" id="label1"/>
</mx:AddChild>
<mx:AddChild position="lastChild">
</mx:AddChild>
<mx:AddChild position="lastChild">
<mx:LinkButton label="编辑" fontSize="12" left="10" bottom="10"/>
</mx:AddChild>
<mx:AddChild position="lastChild">
<mx:Label x="76" y="10" text="ForrestSun" fontSize="12"/>
</mx:AddChild>
<mx:AddChild position="lastChild">
<mx:Label x="76" y="38" text="3" fontSize="12"/>
</mx:AddChild>
<mx:SetProperty name="width" value="254"/>
<mx:SetProperty name="height" value="176"/>
<mx:AddChild position="lastChild">
<mx:Button label="退出" enabled="true" right="10" width="54" top="100" buttonDown="LogOffWindow();"/>
</mx:AddChild>
</mx:State>
</mx:states>
<mx:Label text="用户名:" left="6" top="16" fontSize="12" width="62" id="label0"/>
<mx:Label text="密码:" left="20" top="45" fontSize="12" width="52" id="label3"/>
<mx:TextInput y="12" left="56" right="10" id="txtUser"/>
<mx:TextInput y="45" displayAsPassword="true" left="56" right="10" id="txtPwd"/>
<mx:Button label="登录" width="55" fontSize="12" id="cmdLogIn" click="LoginWindow();" right="73" top="79" height="22"/>
<mx:Button label="取消" width="55" fontSize="12" id="cmdCancel" right="10" top="79" height="22"/>
<mx:Label color="#ff0000" fontSize="12" id="lblInfo" bottom="4" left="10" right="10"/>
</mx:Panel>
写这个主要是今天学习了STATE(状态),同时对实现自定义组件的复习
在上面的代码主最重要有三点:
一、代码改变状态
采用this.currentState="LogOff"; 来改变成登录后的状态
二、this.currentState="";代表的含义
原来我加了一个LOGIN的状态,因为不知道如何获取基本状态(BASESTATE)
查了帮助后得知,想要获取基本状态(呵呵,不知道翻译的对不对)只要将其设置为空就可以,至此这个题目的学习暂告一阶段,我会不断来完善它:)因为它还有很多功能需要挖掘,但由于自己知识还不够,所以努力ing...
三、在<mx:application 中加入 initialize="initApp();" 事件
在mx:script中加入函数
public function initApp():void
{
this.txtUser.setFocus();
}
采用程序初始化时指定用户名输入文本框获取焦点