2011-10-27 90 views
0

我有一小段代码可以从朋友处获得,但是我无法将其转化为工作的AS3.0。无论我改变什么,我总是收到编译器错误。 这是最初的一段代码,我真的很感谢你看看它。将脚本代码从Actionscript 2转换为Actionscript 3

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

如果您发布了特定的编译器错误,它会有所帮助。 – sean

+0

如果您发布迄今为止创建的ActionScript 3代码,它也会有所帮助。 –

回答

2

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

例如:

  • _root在AS3中不存在。在AS3就变成:MovieClip(root)

  • attachMovie是不是在AS3中,你将有一个构造函数调用来取代它像var node = new laser(); ...

  • onPressonRelease回调AS3中不支持。你需要考虑使用addEventListener w/MouseEvent类。同样与onEnterFrameEvent.ENTER_FRAME

  • createEmptyMovieClip()变得new MovieClip();

  • AS3中的图形绘制命令现在嵌套在精灵的graphics对象。

好像你需要深入挖掘AS3这一点。这不是一个非常直接的代码转换。

相关问题