<?xml version="1.0" ?> <!-- Simple example to demonstrate the Transition class. --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <!-- 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:states> <mx:transitions> <!-- Define the transition from the base state to the Register state.--> <mx:Transition id="toRegister" fromState="*" toState="Register"> <mx:Sequence targets="{[loginPanel, registerLink, confirm, loginLink, spacer1]}"> <mx:RemoveChildAction/> <mx:SetPropertyAction target="{loginPanel}" name="title"/> <mx:SetPropertyAction target="{loginButton}" name="label"/> <mx:SetStyleAction target="{loginButton}" name="color"/> <mx:Resize target="{loginPanel}"/> <mx:AddChildAction/> </mx:Sequence> </mx:Transition> <!-- Define the transition from the Register state to the base state.--> <mx:Transition id="toDefault" fromState="Register" toState="*"> <mx:Sequence targets="{[loginPanel, registerLink, confirm, loginLink, spacer1]}"> <mx:RemoveChildAction/> <mx:SetPropertyAction target="{loginPanel}" name="title"/> <mx:SetPropertyAction target="{loginButton}" name="label"/> <mx:SetStyleAction target="{loginButton}" name="color"/> <mx:Resize target="{loginPanel}"/> <mx:AddChildAction/> </mx:Sequence> </mx:Transition> </mx:transitions> <!-- 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:"> <mx:TextInput/> </mx:FormItem> </mx:Form> <mx:ControlBar> <mx:LinkButton id="registerLink" label="Need to Register?" click="currentState='Register'"/> <mx:Spacer width="100%" id="spacer1"/> <mx:Button label="Login" id="loginButton"/> </mx:ControlBar> </mx:Panel> </mx:Application>
Transition 类定义了一组在响应视图状态更改时播放的效果。视图状态的定义定义了如何更改状态,而过渡则定义了在状态更改过程中可视更改发生的顺序。
要定义过渡,可将应用程序的 transitions
属性设置为 Transition 对象的数组。
可使用 Transition 类的 toState
和 fromState
属性来指定触发过渡的状态更改。默认情况下,fromState
和 toState
属性均设置为“*”,表示将过渡应用到视图状态的任何更改。
可以使用 fromState
属性来明确指定要从中进行更改的视图状态,使用 toState
属性来明确指定要更改到的视图状态。如果状态更改和两个过渡匹配,则 toState
属性优先于 fromState
属性。如果超过一个过渡匹配,Flex 将使用过渡数组中的第一个定义。
可以使用 effect
属性来指定应用过渡时要播放的 Effect 对象。通常,它是一个包含多个效果的复合效果对象(如 Parallel 或 Sequence 效果),如下例所示:
<mx:Transition id="myTransition" fromState="*" toState="*"> <mx:Parallel> ... </mx:Parallel> </mx:Transition>