【问题标题】:Need to convert code from AS2 to AS3需要将代码从 AS2 转换为 AS3
【发布时间】:2013-07-18 17:09:15
【问题描述】:
stop();
speed = 10;
initial_width = 75;
target_width = 450;
sp = rect1._x;
this.createEmptyMovieClip("emptymc", 0);
emptymc.onEnterFrame = function() { 
for (i=1; i<=6; i++) {
    if (_root.hit.hitTest(_root._xmouse, _root._ymouse, true)) {
        if (_root["rect"+i].hitTest(_root._xmouse, _root._ymouse, true)) {
            new_x = (_root.sp-(75*(i-1)))-rect1._x;
            rect1._x += new_x/speed;
            n_width = target_width-_root["rect"+i]._width;
            _root["rect"+i]._width += n_width/speed;
        } else {
            n_width2 = initial_width-_root["rect"+i]._width;
            _root["rect"+i]._width += n_width2/speed;
        }
    } else {
        new_x = _root.sp-rect1._x;
        rect1._x += new_x/(speed+50);
        n_width2 = initial_width-_root["rect"+i]._width;
        _root["rect"+i]._width += n_width2/(speed-1);
    }
    _root["rect"+(i+1)]._x = _root["rect"+i]._x+_root["rect"+i]._width;
    _root["movie"+i]._x = _root["rect"+i]._x-1;
    }
};

谢谢大家,我明白了!我尝试翻译为 AS3,似乎一切都很好。仍然有一些小错误,但我会尽力找到它,对于给您带来的不便,我深表歉意。 :(

再次感谢大家。 :)。

【问题讨论】:

  • 迁移该代码所需的所有信息都应在此处。 adobe.com/devnet/flash/articles/first_as3_application.html。祝你好运!如果您有特定问题,请更新您的问题。
  • 亲爱的乔纳坦·赫德伯格!首先,非常感谢您。但我刚开始使用 Flash..我明天必须提交作业。那么,您现在可以帮我把这段代码翻译成 as3 代码吗?我真的很感激! :(
  • 恐怕我们无法为您编写程序或翻译代码...只是一个函数左右,当您遇到更多问题时具体的。这些论坛实际上只是为了在出现更具体的问题时提供帮助。对不起,伙计,您需要先认真尝试自己做,如果您有问题,请告诉我们。
  • @Panzercrisis:谢谢兄弟,我明白了!我尝试翻译为 AS3,似乎一切都很好。还有一些小错误,但我会尽力找到它。再次感谢兄弟。 :)

标签: flash flash-cs5


【解决方案1】:

我的代码不完整,但可以帮助您。 您需要将名为“rect”的影片剪辑放入名为“rects”的数组中,并将名为 movie 的影片剪辑放入名为 movies 的数组中。

前缀为“_root”的变量和影片剪辑必须声明为全局变量。

stop();
speed = 10;
initial_width = 75;
target_width = 450;
sp = rect1._x;

emptymc = new MovieClip();
emptymc.addEventListener (Event.ENTER_FRAME , onEnterFrame);

function onEnterFrame (e:Event):void{

    for (var i:int=1; i<=6; i++) {
        if (hit.hitTestPoint(stage.mouseX, stage.mouseY,true)) {

            if (rect.hitTestPoint(stage.mouseX, stage.mouseY, true)) {
                new_x = (sp-(75*(i-1)))-rect1._x;
                rect1.x += new_x/speed;
                n_width = target_width-rects[i].width;
                rects[i]._width += n_width/speed;
            } else {
                n_width2 = initial_width-rects[i].width;
                rects[i].width += n_width2/speed;
            }

        } else {

            new_x =sp-rect1.x;
            rect1._x += new_x/(speed+50);
            n_width2 = initial_width-rects[i].width;
            rects[i].width += n_width2/(speed-1);
        }

        rects[(i+1)].x = rects[i].x+rects[i].width;
        movies[i].x = rects[i].x-1;
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-14
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 2015-07-15
    相关资源
    最近更新 更多