【问题标题】:Event when Spark transtion ends not getting sentSpark 转换结束时未发送的事件
【发布时间】:2015-02-03 02:04:07
【问题描述】:

我正在尝试获取有关 Spark 转换何时开始和结束的通知。根据ViewTransitionBase 的 Adob​​e 文档,我应该能够做到这一点。

我尝试将事件侦听器添加到我的组件、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>

【问题讨论】:

    标签: actionscript-3 apache-flex flex4


    【解决方案1】:

    我尝试向 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>
    

    【讨论】:

    • 啊,是的!感谢您抽出宝贵的时间。问题出在我的代码中(也许是我的星星......这个项目)。我没有在收听EffectEventevent,甚至在我的任何搜索中都没有提到它。
    猜你喜欢
    • 2011-10-25
    • 2011-10-16
    • 2016-05-10
    • 2016-06-18
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    • 2020-07-30
    • 1970-01-01
    相关资源
    最近更新 更多