我正在尝试获取Spark转换开始和结束的时间。根据{{3}}的Adobe文档,我应该能够做到这一点。
我尝试向我的组件,Parallel
实例和Resize
效果添加事件侦听器,但从未收到任何事件。
我这样做是错误的还是这些事件只有在AS3中完全创建转换时才可能?上面的链接上有一个注释:"在ActionScript中创建和配置视图过渡;你无法在MXML中创建它们。" - 但显然我可以在MXML中创建过渡 - 它们工作正常 - 我能够添加事件监听器 - 那么是什么给出了?
myResize.addEventListener(FlexEvent.TRANSITION_END, onTransitionEnd);
myResize.addEventListener(FlexEvent.TRANSITION_START, onTransitionStart);
<s:states>
<s:State name="window"/>
<s:State name="fullscreen"/>
</s:states>
<s:transitions>
<!-- zoom transition from/to each state -->
<s:Transition id="myTransition" fromState="*" toState="*">
<s:Parallel id="zoomer" targets="{[this]}">
<s:Move duration="300" autoCenterTransform="true"/>
<s:Resize id="myResize" duration="300" />
</s:Parallel>
</s:Transition>
</s:transitions>
答案 0 :(得分:2)
我尝试向Spark过渡添加事件,但效果非常好。我认为问题可能出在你的代码中。
举个例子:Adobe.com : simple transition,我编辑添加事件:
<?xml version="1.0" ?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark" width="400" creationComplete="init(event)">
<fx:Script>
<![CDATA[
import mx.events.EffectEvent
private const newline:String = String.fromCharCode(13)
private function init(event:FlexEvent):void
{
resize_effect.addEventListener(EffectEvent.EFFECT_START, function(e:EffectEvent):void
{
set_log_text('resize effect : start')
})
resize_effect.addEventListener(EffectEvent.EFFECT_END, function(e:EffectEvent):void
{
set_log_text('resize effect : end')
})
}
private function move_effect_start_handler(e:EffectEvent):void
{
set_log_text('move effect : start')
}
private function move_effect_end_handler(e:EffectEvent):void
{
set_log_text('move effect : end')
}
private function set_log_text(txt:String):void
{
txt_log.text += newline + txt
}
]]>
</fx:Script>
<!-- Define the two view states, in addition to the base state.-->
<s:states>
<s:State name="default"/>
<s:State name="One"/>
<s:State name="Two"/>
</s:states>
<!-- Define Transition array with one Transition object.-->
<s:transitions>
<!-- A transition for changing from any state to any state. -->
<s:Transition id="myTransition" fromState="*" toState="*">
<!-- Define a Parallel effect as the top-level effect.-->
<s:Parallel id="t1" targets="{[p1,p2,p3]}">
<!-- Define a Move and Resize effect.-->
<s:Move duration="400" effectStart="move_effect_start_handler(event)" effectEnd="move_effect_end_handler(event)" />
<s:Resize duration="400" id="resize_effect"/>
</s:Parallel>
</s:Transition>
</s:transitions>
<!-- Define the container holding the three Panel containers.-->
<s:Group id="pm" width="100%" height="100%">
<s:Panel id="p1" title="One"
x="0" y="0"
x.One="110" y.One="0"
x.Two="0" y.Two="0"
width="100" height="100"
width.One="200" height.One="210"
width.Two="100" height.Two="100"
click="currentState='One'">
<s:Label fontSize="24" text="One"/>
</s:Panel>
<s:Panel id="p2" title="Two"
x="0" y="110"
x.One="0" y.One="0"
x.Two="110" y.Two="0"
width="100" height="100"
width.One="100" height.One="100"
width.Two="200" height.Two="210"
click="currentState='Two'">
<s:Label fontSize="24" text="Two"/>
</s:Panel>
<s:Panel id="p3" title="Three"
x="110" y="0"
x.One="0" y.One="110"
x.Two="0" y.Two="110"
width="200" height="210"
width.One="100" height.One="100"
width.Two="100" height.Two="100"
click="currentState='default'">
<s:Label fontSize="24" text="Three"/>
</s:Panel>
<s:TextArea id="txt_log" includeIn="default,One,Two" x="28" y="237" width="330" height="300" />
</s:Group>
</s:Application>