开发者

In ActionScript, how to make something move somewhere and move back?

Using Tween class maybe? I tried the easeOut. But if will write 2 Tween, the 2nd one will overwrite the 1st one, so I only see the obj moving in the 2nd Tween direction, not the 1st Tween direction.

I know the coordinates for the 2nd Tween below is not correct (because all coordinates should follow the defined referen开发者_StackOverflow社区ce point), so I need to find out the logo's width and height. But is alright now because it is for testing purpose.

import fl.transitions.Tween;
import fl.transitions.easing.*;
logo.visible = false;
addChild(logo);

circle.addEventListener(MouseEvent.CLICK, moveObj);

function moveObj(e:MouseEvent):void{
    logo.visible = true;
    var tweenRight:Tween = new Tween(logo,"x",None.easeOut, 100, 300, 2, true);
    var tweenLeft:Tween = new Tween(logo,"x",None.easeOut, 300, 100, 2, true);

}


You are firing the two tweens at the same time so you can for example listen to motion finish event and launch the other tween at this moment:

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

logo.visible = false;
addChild(logo);

circle.addEventListener(MouseEvent.CLICK, moveObj);

function moveObj(e:MouseEvent):void{
    logo.visible = true;
    var tweenRight:Tween = new Tween(logo,"x",None.easeOut, 100, 300, 2, true);
    tweenRight.addEventListener(TweenEvent.MOTION_FINISH, onTweenRightFinished);
}
function onTweenRightFinished(e:TweenEvent):void {
    e.currentTarget.removeEventListener(TweenEvent.MOTION_FINISH, onTweenRightFinished);
    var tweenLeft:Tween = new Tween(logo,"x",None.easeOut, 300, 100, 2, true);
}


You have both these happening at the same time, you'll need to delay the second one till after the first ends.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜