【问题标题】:Flex 4 Move Effect only animating last target in array of multiple itemsFlex 4移动效果仅对多个项目数组中的最后一个目标进行动画处理
【发布时间】:2011-06-22 01:10:51
【问题描述】:

我正在使用移动效果为许多项目设置动画。在将每个项目添加到显示列表之后,我将每个项目添加到一个数组中,并且一旦添加了所有项目,调用 play 方法,将一个项目数组传递给它。

只有最后一个项目在我的动画中播放。

这是我的代码:

MXML: s:Move id="coinFall" yFrom="-400" duration="2000" />

public function showCoins(n:Number):void{
            holder.removeAllElements();
            var targets:Array = [];
            if (n>=2.5){
                var coins:uint = Math.round(n/2.5);
                for (var i:uint = 0; i<coins; i++){

                    var c:Coin = new Coin();
                    c.y = 0 - (i*15);
                    holder.addElement(c);
                    targets.push(c);
                }
                coinFall.play(targets); 
            }
        }

非常感谢任何帮助。 谢谢

【问题讨论】:

    标签: apache-flex actionscript-3 animation move effect


    【解决方案1】:

    没有更完整的代码很难说,但这个示例对我有用:

    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark">  
    
        <fx:Declarations>
            <s:Move id="coinFall" yBy="100" duration="2000" />
            <fx:Component className="Coin">
                <s:Ellipse width="50" height="50">
                    <s:fill>
                        <s:SolidColor color="red" />
                    </s:fill>
                </s:Ellipse>
            </fx:Component>
        </fx:Declarations>
        <fx:Script>
            <![CDATA[
                public function showCoins(n:Number):void{
                    holder.removeAllElements();
                    var targets:Array = [];
                    for (var i:uint = 0; i<n; i++){
                        var c:Coin = new Coin();
                        c.x = i*50;
                        c.y = 0 - i*10;
                        holder.addElement(c);
                        targets.push(c);
                    }
                    coinFall.play(targets); 
                }
            ]]>
        </fx:Script>
    
        <s:controlBarContent>
            <s:Button label="play" click="showCoins(5)" />
        </s:controlBarContent>
    
        <s:Group id="holder" />
    
    </s:Application>
    

    我建议考虑在移动效果上使用 yBy/yTo。

    【讨论】:

    • 嗨 Steven,在 'showCoins()' 之外声明可绑定变量 'targets' 并将其作为 target='{targets}' 传递给 'coinFall' 效果的优点/缺点是什么?
    • 我认为不会有任何特定的优点/缺点,两种方法应该作用相同。您在此处的方法避免了额外的绑定,这通常是获得更好性能的好习惯。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-24
    • 1970-01-01
    • 2015-02-01
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 2017-07-25
    相关资源
    最近更新 更多