11.2.为进入和离开States创建Transitions

11.2.1. 问题
我想创建一个特效,当进入或退出state 时进行播放
11.2.2. 解决办法
使用Transitions 对象,设置其fromState 和toState 属性。
11.2.3. 讨论
一个transition 就是一个特效或一系列特效。Transition 对象给出了fromState 和toState 属性定义何时播放。fromState 和toState 属性及可以是特定的states 或通配符(*)。

有几个方法创建Transition 对象,添加一个特效到组件,绑定Transition 的effect 属性到特效。

下面的代码定义了一个Transition,其effect 属性绑定到id 为glow 的特效上。
+展开
-XML
<mx:Transition id="thirdTransfromState="edittoState="showeffect="{glow}"/>

就像State 那样,一个Transition 对象定义被执行的行为。该行为需要一个目标,但是这个目标并不是Tansition 本身的一部分。你可以在Transition 中添加SetPropertyStyle 或SetPropertyAction 来改变样式或当前组件的子组件属性如height 或width 等:
+展开
-XML
<mx:Transition id="firstTransfromState="showtoState="edit">
<mx:SetPropertyAction target="{holder}name="alphavalue="0"/>
</mx:Transition>

使用SetStyleAction 时Transition 将设置目标组件的style 属性:
+展开
-XML
<mx:Transition id="secondTransfromState="*toState="upload">
<mx:SetStyleAction target="{holder}name="backgroundColorvalue="#ff0000"/>
</mx:Transition>

下面的代码创建三个States,定义Transition 对象在各个states 之间切换:
+展开
-XML
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxmlwidth="400height="300currentState="show">
<mx:Script>
<![CDATA[
[Bindable]
private var _imgURL:String;
[Bindable]
private var _title:String;

]]>
</mx:Script>
<mx:Glow blurXTo="20blurYTo="20duration="1000"
color="0xffff00id="glowtarget="{holder}"/>

<mx:Glow blurXTo="25blurYTo="25duration="1000"
color="0xffffffid="fadetarget="{holder}"/>

这里定义了多个Transition 对象,设置了fromState 和toState 属性,指示何时播放:
+展开
-XML
<mx:transitions>
<mx:Transition id="firstTransfromState="show"
toState="edit">

<mx:SetPropertyAction target="{holder}name="alpha"
value="0"/>

</mx:Transition>
<mx:Transition id="secondTransfromState="*"
toState="upload">

<mx:SetStyleAction target="{holder}"
name="backgroundColorvalue="#ff0000"/>

</mx:Transition>
<mx:Transition id="thirdTransfromState="edit"
toState="showeffect="{glow}"/>

<mx:Transition id="fifthTransfromState="upload"
toState="*effect="{fade}"/>

</mx:transitions>
<mx:states>
<mx:State/>
<mx:State name="show">
<mx:AddChild relativeTo="{holder}">
<mx:HBox>
<mx:Label text="{_title}"/>
<mx:Image source="{_imgURL}"/>
</mx:HBox>
</mx:AddChild>
</mx:State>
<mx:State name="editexitState="_title = input.text;">
<mx:AddChild relativeTo="{holder}">
<mx:HBox>
<mx:TextInput id="inputtext="{_title}"/>
</mx:HBox>
</mx:AddChild>
</mx:State>
<mx:State name="upload">
<mx:AddChild relativeTo="{holder}">
<mx:HBox>
<mx:Button label="start upload"/>
</mx:HBox>
</mx:AddChild>
</mx:State>
</mx:states>
<mx:ComboBox dataProvider="{[''show', 'edit', 'upload']}"
change="{this.currentState = cb.selectedItem as String}"
id="cb"/>

<mx:Canvas id="holder"/>
</mx:HBox>

加支付宝好友偷能量挖...


评论(0)网络
阅读(80)喜欢(0)flash/flex/fcs/AIR