flex4 State与Transition

在状态切换的时候,要给组件不同为位置、颜色加上过渡效果,需要用到Transition,其中fromState和toState用来指定起始状态,当状态发生切换时,将触发其中的过渡效果。
下面是切换时位移效果(奇怪的是为Transition添加autoReverse="true",没有起作用,只好写个起始状态相反的Transition来代替,不知错在哪里?):
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
	<s:layout>
		<s:BasicLayout/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			import mx.events.MoveEvent;
			protected function button1_clickHandler(event:MouseEvent):void
			{
				// TODO Auto-generated method stub
				if(currentState=="State1")
				currentState="State2";
				else
					currentState="State1";
			}

		]]>
	</fx:Script>
	<s:states>
		<s:State name="State1"/>
		<s:State name="State2"/>
	</s:states>

	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<s:Button x.State1="77" x.State2="633" y="172" id="button" label="按钮" click="button1_clickHandler(event)"   label.State2="按钮" />
	<s:Label includeIn="State2" x="633" y="152" text="状态2" width="70"/>
	<s:Label includeIn="State1" x="77" y="152" text="状态1"/>
	<s:transitions   >
		<s:Transition fromState="State1" toState="State2"  >
			<s:Parallel target="{button}" >
				<s:Move duration="1000" xFrom="{x['State1']}" xTo="{x['State2']}" />
			</s:Parallel>
		</s:Transition>
		<s:Transition fromState="State2" toState="State1"  >
			<s:Parallel target="{button}" >
				<s:Move duration="1500" xFrom="{x['State2']}" xTo="{x['State1']}" />
			</s:Parallel>
		</s:Transition>
	</s:transitions>
</s:Application>

参考flex3:
http://www.adobe.com/livedocs/flex/3_cn/mx/states/Transition.html#mxmlSyntaxSummary

你可能感兴趣的:(html,xml,Flex,Adobe)