2014-12-05 24 views
0

我试图获取Spark转换何时开始和结束的通知。根据Adobe文档ViewTransitionBase,我应该可以做到这一点。Spark转换结束时未发送的事件

我已经尝试添加事件侦听器来我的组件,到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> 

回答

2

我试着添加事件,星火过渡和它的工作非常出色。我认为问题可能出现在您的代码中。

拿这个例子: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> 
+0

是啊!感谢您抽出宝贵的时间。错误在我的代码中(也许是我的明星......在这个项目中)。我没在听EffectEvent事件,甚至在我的任何搜索中都没有提到这一点。 – 2014-12-05 03:48:05