<?xml version="1.0" ?>
<!-- Simple example to demonstrate the States class. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import flash.events.MouseEvent;
internal function newClick(event:MouseEvent):void
{
Alert.show("这是一个新状态!","tips");
}
]]>
</mx:Script>
<!-- Define one view state, in addition to the base state.-->
<mx:states>
<mx:State name="Register">
<mx:AddChild relativeTo="{loginForm}" position="lastChild">
<mx:target>
<mx:FormItem id="confirm" label="Confirm:">
<mx:TextInput/>
</mx:FormItem>
</mx:target>
</mx:AddChild>
<mx:SetProperty target="{loginPanel}" name="title" value="Register"/>
<mx:SetProperty target="{loginButton}" name="label" value="Register"/>
<mx:SetStyle target="{loginButton}"
name="color" value="blue"/>
<mx:RemoveChild target="{registerLink}"/>
<mx:AddChild relativeTo="{spacer1}" position="before">
<mx:target>
<mx:LinkButton id="loginLink" label="Return to Login" click="currentState=''"/>
</mx:target>
</mx:AddChild>
</mx:State>
<mx:State name="newstate">
<mx:SetProperty target="{loginPanel}" name="height" value="287"/>
<mx:RemoveChild target="{formitem1}"/>
<mx:AddChild relativeTo="{loginForm}" position="lastChild">
<mx:FormItem label="输入邮箱:" fontSize="12">
<mx:TextInput/>
</mx:FormItem>
</mx:AddChild>
<mx:AddChild relativeTo="{loginForm}" position="lastChild" >
<mx:FormItem label="Label">
<mx:Button label="Button" id="newBtn"/>
</mx:FormItem>
</mx:AddChild>
<mx:SetProperty target="{loginPanel}" name="title" value="newstate"/>
<mx:SetEventHandler target="{registerLink}" name="click" handler="currentState=''"/>
<mx:SetEventHandler target="{newBtn}" name="click" handlerFunction="newClick"/>
</mx:State>
</mx:states>
<!-- Define a Panel container that defines the login form.-->
<mx:Panel title="Login" id="loginPanel"
horizontalScrollPolicy="off" verticalScrollPolicy="off"
paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
<mx:Text width="100%" color="blue"
text="Click the 'Need to Register?' link to change state. Click the 'Return to Login' link to return to the base state."/>
<mx:Form id="loginForm" >
<mx:FormItem label="Username:">
<mx:TextInput/>
</mx:FormItem>
<mx:FormItem label="Password:" id="formitem1">
<mx:TextInput/>
</mx:FormItem>
</mx:Form>
<mx:ControlBar id="controlbar1">
<mx:LinkButton id="registerLink" label="Need to Register?"
click="currentState='newstate'"/>
<mx:Spacer width="100%" id="spacer1"/> /*Spacer 控件,使用灵活的 Spacer 控件将 Button 控件推到右侧,以便 Button 控件与 HBox 容器的右边对齐*/
* <mx:Button label="Login" id="loginButton"/>
</mx:ControlBar>
</mx:Panel>
</mx:Application>
以上为state的使用,规定不同状态,通常与transitition(规定状态切换顺去)一起使用/
①在addchild属性中有creationpolicy即“创建策略”,共有4个值:auto ,all, queued ,none,分别表示 : 需要此对象是创建 ;总是创建对象; 对象完成初始化才开始创建子机元素;不创建对象。
② /*Spacer 控件,使用灵活的 Spacer 控件将 Button 控件推到右侧,以便 Button 控件与 HBox 容器的右边对齐*/