在 ActionScript 中,如何使某物移动到某处并移回?

发布于 2024-08-19 17:42:13 字数 574 浏览 11 评论 0原文

也许使用 Tween 类?我尝试了easeOut。但是如果写2个Tween,第二个会覆盖第一个,所以我只能看到obj在第二个Tween方向移动,而不是第一个Tween方向。

我知道下面第二个补间的坐标不正确(因为所有坐标都应遵循定义的参考点),所以我需要找出徽标的宽度和高度。但现在没关系,因为它是用于测试目的。

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);

}

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 reference 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);

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

め可乐爱微笑 2024-08-26 17:42:13

您同时触发两个补间,因此您可以收听 motion finish 事件并在此时启动另一个补间:

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 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);
}
难以启齿的温柔 2024-08-26 17:42:13

这两个事件同时发生,您需要将第二个事件推迟到第一个事件结束之后。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文