0

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);
};
2
  • It would help if you post the specific compiler errors you're getting. Commented Oct 27, 2011 at 15:54
  • It would also help if you post the Actionscript 3 code that you've created so far. Commented Oct 27, 2011 at 16:14

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.