Flex 4 Move Effect only animating last target in array of multiple items
I am a开发者_如何学JAVAnimating a number of items using the Move effect. I am adding each item to an array after it has been added to the display list and once all items are added calling the play method, passing an array of the items to it.
Only the last item plays in my animation.
Here is my code:
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);
}
}
Any help much appreciated. Thanks
It's hard to tell without more complete code, but this sample works for me:
<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>
I would suggest looking into using yBy/yTo on the Move effect.
精彩评论