import mx.transitions.Tween;
import mx.transitions.easing.*;
Stage.scaleMode = "noScale";
var aClass=[Back,Bounce,Elastic,Regular,Strong];
var aEasingMethod:Array=new Array();
//在aEasingMethod中放入每个缓动方法
for(i=0; i < aClass.length; i++){
aEasingMethod.push(aClass[i].easeIn);
aEasingMethod.push(aClass[i].easeOut);
aEasingMethod.push(aClass[i].easeInOut);
}
//定义初始变量
var nX=10;
var Y=200;
var oClips:Object=new Object();
建立侦听器
var tListener:Object=new Object();
tListener.onMotionFinished=function(twObject:Tween){
//缓动结束时按原路径返回
twObject.yoyo();
}
for(i=0; i < aEasingMethod.length; i++){
depth=this.getNextHighestDepth();
mClip=this.attachMovie("ball","ball"+i,depth,{_x:nX,_y:Y});
//设置x坐标
nX+=mClip._width+10;
if(nX>=Stage.width-_root["ball0"]._width){
nX = 10;
Y += 20;
}
//将一个缓动方法添加到oClips对象
oClips[mClip._name]=aEasingMethod[i];
trace("ball"+i + ": " + mClip);
//当用户点击时开始_y属性的补间
mClip.onPress=function(){
var twMove:Tween = new Tween(this,"_xscale",oClips[this._name],20,800,4,true);
//添加侦听器
twMove.addListener(tListener);
var twMove:Tween = new Tween(this,"_yscale",oClips[this._name],20,800,4,true);
//添加侦听器
twMove.addListener(tListener);
trace(this._name);
}
}