翻译code从ActionScript 2到ActionScript 3的 [英] Translating code from Actionscript 2 to Actionscript 3

查看:344
本文介绍了翻译code从ActionScript 2到ActionScript 3的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的小块code,我从一个朋友得到了,但我不能管理它转化为工作AS3.0。我一直不管我改变很多编译器错误。 原来这是一张code和我真的AP preciate你拖尾看一个吧。

  laser_nodes = 2;
为(变种X = 1; X&其中; = laser_nodes; X ++){
    节点= _root.attachMovie(激光,激光_+ X,X,{_x:的Math.random()* 460 + 20,_y:的Math.random()* 310 + 20});
    node.on preSS =功能(){
        的startDrag(本);
    };
    node.onRelease =功能(){
        调用stopDrag();
    };
}

_root.createEmptyMovieClip(线,_root.getNextHighestDepth());

ray.onEnterFrame =功能(){
    this.clear();
    this.lineStyle(3,为0xFF0000);
    this.moveTo(_root.laser_1._x,_root.laser_1._y);
    为(X = 2; X&其中; = laser_nodes; X ++){
        this.lineTo(_root [激光_+ X] ._ X,_root [激光_+ X] ._ y)的;
    }
    this.lineTo(_root.laser_1._x,_root.laser_1._y);
};
 

解决方案

有很多问题在这里。有些是语法,在别人需要新的方法。

例如:

  • _root 在AS3中不存在。在AS3就变成:影片剪辑(根)

  • 的attachMovie 是不是在AS3用,你就必须将它与像 VAR节点=新的激光构造函数调用替换( ); ...

  • 在preSS onRelease 回调不支持AS3。你需要考虑使用的addEventListener 瓦特/ 的MouseEvent 类。同样的,的onEnterFrame Event.ENTER_FRAME

  • createEmptyMovieClip()变成新的MovieClip();

  • 的精灵

    现在嵌套在显卡在AS3的图形绘制命令对象。

看起来像你需要深入AS3一点点这个。这不是code一个非常简单的位来转换。

I have this small piece of code I got from a friend, but i can't manage to translate it into working AS3.0. I keep getting compiler errors no matter what i change. This is the original piece of code and I would really appreciate you tailing a look at a it.

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

解决方案

There are a lot of issues here. Some are syntactical, where others require new methods.

for instance:

  • _root does not exist in AS3. In AS3 it becomes: MovieClip(root)

  • attachMovie is not available in AS3, you'll have to replace it with a constructor call like var node = new laser(); ...

  • onPress and onRelease callbacks are not supported in AS3. you'll need to look into using the addEventListener w/ the MouseEvent class. Same with onEnterFrame (Event.ENTER_FRAME)

  • createEmptyMovieClip() becomes new MovieClip();

  • the graphic drawing commands in AS3 are now nested in the graphics object of Sprites.

Seems like you'll need to dig into AS3 a little bit for this. It's not a very straight forward bit of code to convert.

这篇关于翻译code从ActionScript 2到ActionScript 3的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆