舞台上有9个影片剪辑,有两帧,第一帧加stop();
实例名分别为mc1/mc2/mc3...mc9
在帧上加如下代码:
import fl.transitions.Tween;
import fl.motion.easing.Quadratic;
import fl.transitions.TweenEvent;
var time:Number=0.3;//切换时间
var startId:int=0;
var endId:int=0;
var clickCount:int=0;
var isMove:Boolean=false;
var tweenAry:Array=new Array();
for(var i:int=1;i<10;i++)
{
this["mc"+i].addEventListener(MouseEvent.CLICK,MouseClickEvent);
}
function MouseClickEvent(e:MouseEvent):void
{
var obj:Object=e.currentTarget;
var t:int=int(obj.name.slice(2));
if(t==startId||t==endId)
{
obj.gotoAndStop(1);
clickCount--;
if(t==startId)
{
startId=0;
}
else if(t==endId)
{
endId=0;
}
return;
}
obj.gotoAndStop(2);
if(clickCount==0)
{
startId=t;
}
else
{
endId=t;
}
clickCount++;
if(clickCount==2)
{
isMove=true;
tweenAry.push(new Tween(this["mc"+startId], "x", Quadratic.easeInOut, this["mc"+startId].x,this["mc"+endId].x,time, true));
tweenAry.push(new Tween(this["mc"+startId], "y", Quadratic.easeInOut, this["mc"+startId].y,this["mc"+endId].y,time, true));
tweenAry.push(new Tween(this["mc"+endId], "x", Quadratic.easeInOut, this["mc"+endId].x,this["mc"+startId].x,time, true));
tweenAry.push(new Tween(this["mc"+endId], "y", Quadratic.easeInOut, this["mc"+endId].y,this["mc"+startId].y,time, true));
tweenAry[tweenAry.length-1].addEventListener(TweenEvent.MOTION_FINISH,MoveEndEvent);
}
}
function MoveEndEvent(e:TweenEvent):void
{
isMove=false;
this["mc"+startId].gotoAndStop(1);
this["mc"+endId].gotoAndStop(1);
clickCount=0;
startId=0;
endId=0;
}