AS2:在运动完成之前不要执行推出

发布于 2024-11-16 09:10:17 字数 2407 浏览 1 评论 0原文

我有一个MC,应用了一些补间,但是如果你在它们完成之前推出它们,它们就会破裂。我不想在补间运行时禁用该按钮,因为如果您在补间运行时推出该按钮,则会让用户感到困惑,因为什么也没有发生,您就会陷入该帧中。

我想要的是在补间期间(或之后)确认推出,但在补间完成之前不运行。然而,我似乎无法从 rollout 函数访问 rollover 函数中补间的 onmotionfinished 。

有什么想法吗?

如果有帮助的话,那就是我的翻转:

    buttons[i].onRollOver = function() {
    var oppX:Number = Stage.width-this._x;
    var oppY:Number = Stage.height-this._y;
    if (oppX-209.8<=20) {
        var difference:Number = Math.abs(20-(oppX-209.8));
        oppX += difference;
    } else if (oppX+209.8>=780) {
        var difference:Number = Math.abs(780-(oppX+209.8));
        oppX -= difference;
    }
    if (oppY-172.1<=20) {
        var difference:Number = Math.abs(20-(oppY-172.1));
        oppY += difference;
    } else if (oppY+172.1>=580) {
        var difference:Number = Math.abs(580-(oppY+172.1));
        oppY -= difference;
    }
    var TweenX:Tween = new Tween(circle, "_x", mx.transitions.easing.Strong.easeOut, circle._x, oppX, 1, true);
    var TweenY:Tween = new Tween(circle, "_y", mx.transitions.easing.Strong.easeOut, circle._y, oppY, 1, true);
    circle.gotoAndPlay("out");
    myColor = new Color(this);
    myColor.setTint(153,255,0,30);
    for (MovieClip in buttons) {
        delete buttons[MovieClip].onEnterFrame;
        if (buttons[MovieClip] != this) {
            buttons[MovieClip].enabled = false;
            myColor = new Color(buttons[MovieClip]);
            myColor.setTint(255,255,255,80);
            myColor = new Color(buttons[MovieClip]._line);
            myColor.setTint(255,255,255,80);
        }
    }

};

和我的推出:

    buttons[i].onRollOut = function() {
    this.onMotionComplete = function() {

    var TweenX:Tween = new Tween(circle, "_x", mx.transitions.easing.Strong.easeOut, circle._x, 400, 0.5, true);
    var TweenY:Tween = new Tween(circle, "_y", mx.transitions.easing.Strong.easeOut, circle._y, 300, 0.5, true);
    TweenY.onMotionFinished = function() {
        for (MovieClip in buttons) {
            buttons[MovieClip].enabled = true;
        }
    };
    this._parent.circle.gotoAndPlay("in");
    for (MovieClip in buttons) {
        buttons[MovieClip].onEnterFrame = function() {
            moveButtons(this);
            controlButtons(this);
        };
        myColor = new Color(buttons[MovieClip]);
        myColor.setTint(255,255,255,0);
    }

};

I have an mc with some tweens applied to it, but if you roll out before they are done they break. I don't want to disable the button while tweens are running because if you roll out while they run you confuse the user because nothing happens and you get stuck in that frame.

What I want is to acknowledge the rollout during the tween (or after) but not run until the tweens are finished. I cannot seem to access the onmotionfinished of the tween in the rollover function from the rollout function however.

Any ideas?

If it helps here is my rollover:

    buttons[i].onRollOver = function() {
    var oppX:Number = Stage.width-this._x;
    var oppY:Number = Stage.height-this._y;
    if (oppX-209.8<=20) {
        var difference:Number = Math.abs(20-(oppX-209.8));
        oppX += difference;
    } else if (oppX+209.8>=780) {
        var difference:Number = Math.abs(780-(oppX+209.8));
        oppX -= difference;
    }
    if (oppY-172.1<=20) {
        var difference:Number = Math.abs(20-(oppY-172.1));
        oppY += difference;
    } else if (oppY+172.1>=580) {
        var difference:Number = Math.abs(580-(oppY+172.1));
        oppY -= difference;
    }
    var TweenX:Tween = new Tween(circle, "_x", mx.transitions.easing.Strong.easeOut, circle._x, oppX, 1, true);
    var TweenY:Tween = new Tween(circle, "_y", mx.transitions.easing.Strong.easeOut, circle._y, oppY, 1, true);
    circle.gotoAndPlay("out");
    myColor = new Color(this);
    myColor.setTint(153,255,0,30);
    for (MovieClip in buttons) {
        delete buttons[MovieClip].onEnterFrame;
        if (buttons[MovieClip] != this) {
            buttons[MovieClip].enabled = false;
            myColor = new Color(buttons[MovieClip]);
            myColor.setTint(255,255,255,80);
            myColor = new Color(buttons[MovieClip]._line);
            myColor.setTint(255,255,255,80);
        }
    }

};

and my rollOut:

    buttons[i].onRollOut = function() {
    this.onMotionComplete = function() {

    var TweenX:Tween = new Tween(circle, "_x", mx.transitions.easing.Strong.easeOut, circle._x, 400, 0.5, true);
    var TweenY:Tween = new Tween(circle, "_y", mx.transitions.easing.Strong.easeOut, circle._y, 300, 0.5, true);
    TweenY.onMotionFinished = function() {
        for (MovieClip in buttons) {
            buttons[MovieClip].enabled = true;
        }
    };
    this._parent.circle.gotoAndPlay("in");
    for (MovieClip in buttons) {
        buttons[MovieClip].onEnterFrame = function() {
            moveButtons(this);
            controlButtons(this);
        };
        myColor = new Color(buttons[MovieClip]);
        myColor.setTint(255,255,255,0);
    }

};

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

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

发布评论

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

评论(1

动次打次papapa 2024-11-23 09:10:17

意识到大部分问题并不是由补间引起的,而是 gotoandplay 因为我有 stop();调用与该影片剪辑上的标记相同的帧,导致它们卡住。

补间确实遇到了一些问题(如果补间被称为中间补间,则卷展栏会跳回到翻转位置),但我决定将补间推送到一个数组,使它们可以全局访问,并清除数组 onmotionfinished 然后在卷展中检查以查看是否该数组包含任何内容,如果是这样,请先杀死旧的补间。

最终产品:

    buttons[i].onRollOver = function() {
    circle.active = this;
    var oppX:Number = Stage.width-this._x;
    var oppY:Number = Stage.height-this._y;
    if (oppX-209.8<=20) {
        var difference:Number = Math.abs(20-(oppX-209.8));
        oppX += difference;
    } else if (oppX+209.8>=780) {
        var difference:Number = Math.abs(780-(oppX+209.8));
        oppX -= difference;
    }
    if (oppY-172.1<=20) {
        var difference:Number = Math.abs(20-(oppY-172.1));
        oppY += difference;
    } else if (oppY+172.1>=580) {
        var difference:Number = Math.abs(580-(oppY+172.1));
        oppY -= difference;
    }
    var TweenX:Tween = new Tween(circle, "_x", mx.transitions.easing.Strong.easeOut, circle._x, oppX, 1, true);
    var TweenY:Tween = new Tween(circle, "_y", mx.transitions.easing.Strong.easeOut, circle._y, oppY, 1, true);
    TweenY.onMotionFinished = function () {
        tweens.length = 0;
    }
    tweens.push(TweenX,TweenY);
    circle.gotoAndPlay("out");
    myColor = new Color(this);
    myColor.setTint(153,255,0,30);
    for (MovieClip in buttons) {
        delete buttons[MovieClip].onEnterFrame;
        if (buttons[MovieClip] != this) {
            buttons[MovieClip].enabled = false;
            myColor = new Color(buttons[MovieClip]);
            myColor.setTint(255,255,255,80);
            myColor = new Color(buttons[MovieClip]._line);
            myColor.setTint(255,255,255,80);
        }
    }
};
buttons[i].onRollOut = function() {
    if (tweens.length != 0) {
        tweens[0].stop();
        tweens[1].stop();
        delete tweens[0];
        delete tweens[1];
        tweens.length = 0;
    }
    circle.gotoAndPlay("in");
    var TweenX:Tween = new Tween(circle, "_x", mx.transitions.easing.Strong.easeOut, circle._x, 400, 0.5, true);
    var TweenY:Tween = new Tween(circle, "_y", mx.transitions.easing.Strong.easeOut, circle._y, 300, 0.5, true);
    TweenY.onMotionFinished = function() {
        circle._x = 400;
        circle._y = 300;
        for (MovieClip in buttons) {
            buttons[MovieClip].enabled = true;
        }
    };
    for (MovieClip in buttons) {
        buttons[MovieClip].onEnterFrame = function() {
            moveButtons(this);
            controlButtons(this);
        };
        myColor = new Color(buttons[MovieClip]);
        myColor.setTint(255,255,255,0);
    }
};

Realised that it wasn't the tween causing most of the problems that it was the gotoandplay because i had my stop(); calls on the same frame as the markers on that movieclip causing them to get stuck.

Did have some trouble with tween (the rollout jumped back to the rollover position if its tweens were called mid tween) but I decided to push the tweens to an array making them globally accessible and purge the array onmotionfinished then in the rollout check to see if the array contains anything and if so kill off the old tweens first.

Final product:

    buttons[i].onRollOver = function() {
    circle.active = this;
    var oppX:Number = Stage.width-this._x;
    var oppY:Number = Stage.height-this._y;
    if (oppX-209.8<=20) {
        var difference:Number = Math.abs(20-(oppX-209.8));
        oppX += difference;
    } else if (oppX+209.8>=780) {
        var difference:Number = Math.abs(780-(oppX+209.8));
        oppX -= difference;
    }
    if (oppY-172.1<=20) {
        var difference:Number = Math.abs(20-(oppY-172.1));
        oppY += difference;
    } else if (oppY+172.1>=580) {
        var difference:Number = Math.abs(580-(oppY+172.1));
        oppY -= difference;
    }
    var TweenX:Tween = new Tween(circle, "_x", mx.transitions.easing.Strong.easeOut, circle._x, oppX, 1, true);
    var TweenY:Tween = new Tween(circle, "_y", mx.transitions.easing.Strong.easeOut, circle._y, oppY, 1, true);
    TweenY.onMotionFinished = function () {
        tweens.length = 0;
    }
    tweens.push(TweenX,TweenY);
    circle.gotoAndPlay("out");
    myColor = new Color(this);
    myColor.setTint(153,255,0,30);
    for (MovieClip in buttons) {
        delete buttons[MovieClip].onEnterFrame;
        if (buttons[MovieClip] != this) {
            buttons[MovieClip].enabled = false;
            myColor = new Color(buttons[MovieClip]);
            myColor.setTint(255,255,255,80);
            myColor = new Color(buttons[MovieClip]._line);
            myColor.setTint(255,255,255,80);
        }
    }
};
buttons[i].onRollOut = function() {
    if (tweens.length != 0) {
        tweens[0].stop();
        tweens[1].stop();
        delete tweens[0];
        delete tweens[1];
        tweens.length = 0;
    }
    circle.gotoAndPlay("in");
    var TweenX:Tween = new Tween(circle, "_x", mx.transitions.easing.Strong.easeOut, circle._x, 400, 0.5, true);
    var TweenY:Tween = new Tween(circle, "_y", mx.transitions.easing.Strong.easeOut, circle._y, 300, 0.5, true);
    TweenY.onMotionFinished = function() {
        circle._x = 400;
        circle._y = 300;
        for (MovieClip in buttons) {
            buttons[MovieClip].enabled = true;
        }
    };
    for (MovieClip in buttons) {
        buttons[MovieClip].onEnterFrame = function() {
            moveButtons(this);
            controlButtons(this);
        };
        myColor = new Color(buttons[MovieClip]);
        myColor.setTint(255,255,255,0);
    }
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文