簡體   English   中英

將代碼從Actionscript 2轉換為Actionscript 3

[英]Translating code from Actionscript 2 to Actionscript 3

我有一小段我從朋友那里得到的代碼,但我無法將其翻譯成AS3.0。 無論我改變什么,我都會遇到編譯錯誤。 這是原始的代碼片段,我真的很感謝你拖尾看看它。

laser_nodes = 2;
for (var x=1; x<=laser_nodes; x++) {
    node = _root.attachMovie("laser", "laser_"+x, x, {_x:Math.random()*460+20, _y:Math.random()*310+20});
    node.onPress = function() {
        startDrag(this);
    };
    node.onRelease = function() {
        stopDrag();
    };
}

_root.createEmptyMovieClip("ray", _root.getNextHighestDepth());

ray.onEnterFrame = function() {
    this.clear();
    this.lineStyle(3, 0xff0000);
    this.moveTo(_root.laser_1._x, _root.laser_1._y);
    for (x=2; x<=laser_nodes; x++) {
        this.lineTo(_root["laser_"+x]._x, _root["laser_"+x]._y);
    }
    this.lineTo(_root.laser_1._x, _root.laser_1._y);
};

這里有很多問題。 有些是語法,其他人需要新的方法。

例如:

  • AS3中不存在_root 在AS3中它變為: MovieClip(root)

  • attachMovie在AS3中不可用,你必須用一個構造函數調用替換它,如var node = new laser(); ... var node = new laser(); ...

  • AS3不支持onPressonRelease回調。 你需要研究使用帶有MouseEvent類的addEventListener onEnterFrameEvent.ENTER_FRAME )相同

  • createEmptyMovieClip()成為new MovieClip();

  • AS3中的圖形繪制命令現在嵌套在Sprites的graphics對象中。

好像你需要為此深入挖掘AS3。 這不是一個非常直接的代碼轉換。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM