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:
[url]http://www.adobe.com/livedocs/flex/3_cn/mx/states/Transition.html#mxmlSyntaxSummary[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值