-1

我有一个 actionscript 2.0 脚本,但我希望它在 actionscript 3.0 中。

我的脚本:

var speed:Number = 15;
avancar.onPress = function () {
_root.onEnterFrame = function() {
    if(scroll_img._x > -262) {
        scroll_img._x -= speed;
    }
}   
}   

avancar.onRelease = function() {
delete_root.onEnterFrame;
}

voltar.onPress = function () {
_root.onEnterFrame = function() {
    if(scroll_img._x < 56) {
        scroll_img._x += speed;
    }
}
}
voltar.onRelease = function() {
delete_root.onEnterFrame;
}

我尝试了大约 1 小时来找到 actionscript 3.0,但我找不到。如果有人可以帮助我,我会非常高兴。

4

1 回答 1

1

哇,即使在 AS2 中,这段代码也很难看

让我们首先删除内联函数,如下所示:

    avClicked = false;
    vtClicked = false; // these are just triggers

    function moveScrollImg(e:Event):void {
        if ((scroll_img._x > -262) && avClicked) scroll_img.x -= speed;
        if ((scroll_img._x < 56) && vtClicked) scroll_img.x += speed;
    }

    function triggerFlag(e:MouseEvent):void {
        if (e.buttonDown) {
            if (e.target == avancar) avClicked = true;
            if (e.target == voltar) vtClicked = true;
        else {
            avClicked = false;
            vtClicked = false;
        }
    }

    this.addEventListener(Event.ENTER_FRAME, moveScrollImg);
    avancar.addEventListener(MouseEvent.MOUSE_DOWN, triggerFlag);
    voltar.addEventListener(MouseEvent.MOUSE_DOWN, triggerFlag);
    avancar.addEventListener(MouseEvent.MOUSE_UP, triggerFlag);
    voltar.addEventListener(MouseEvent.MOUSE_UP, triggerFlag);

这应该会有所帮助。不要忘记,您必须继承 Sprite 才能使此代码正常工作(或与 EventDispatcher 相关的任何其他类)

于 2013-10-03T20:52:21.900 回答