(ActionScript)移动阵列中的对象,产生体育场波浪效果

时间:2010-01-29 09:58:27

标签: flash actionscript-3 flash-cs4 tween

我想移动阵列中的所有对象产生体育场波浪效果,我该怎么做? 我想根据舞台上的y值移动对象......我的所有正方形都是50x50。我想把它们向上移动然后向下移动它们。 以下是我的代码,请给我建议。谢谢!

import fl.transitions.Tween; 
import fl.transitions.easing.*; 
import fl.transitions.TweenEvent; 

var t1:Timer = new Timer(100, 0); 
var index:int = 0; 
t1.addEventListener(TimerEvent.TIMER, ping); 
t1.start();
var array:Array = new Array();

addToArray();
function addToArray():void {
 for(var i=0; i<10; i++) {
  array[i] = new Sq();
  array[i].x = i*50 + 50;
  array[i].y = 100;
  addChild(array[i]);
 } 
}

function ping(e:TimerEvent) { 
 if(index < array.length){ 
  moveUp(array[index]);
  index ++; 
 } 
} 

function moveUp(sq:Sq):void{ 
    var tweenRight:Tween = new Tween(sq,"y",None.easeOut, sq.y, sq.y - 50, 1, true); 
    tweenRight.addEventListener(TweenEvent.MOTION_FINISH, moveDown); 
}

function moveDown(e:TweenEvent):void {
   //what to put here?
   //or this is not the right way to do this?
}

1 个答案:

答案 0 :(得分:1)

您需要在moveDown函数中抓取补间对象并应用补间动画(增加y)。

function moveDown(e:TweenEvent):void {
  var sq:Sq = Sq(e.target.obj);
  var tweenDown:Tween = new Tween(sq,"y",None.easeOut, sq.y, sq.y + 50, 1, true);
  if (Sq(e.target.obj) === array[array.length - 1]) {
    trace("this is the last tween down");
    tweenDown.addEventListener(TweenEvent.MOTION_FINISH, lastTweenFinish);
  }
}
function lastTweenFinish(e:TweenEvent):void {
  trace("DONE");
}
还有一件事是为什么在moveUp函数中使用Timer t2。