Skip to main content
Participant
March 24, 2011
Question

Help! Convert simple Flash AS2 code to AS3

  • March 24, 2011
  • 1 reply
  • 585 views

Hi everyone,

I'm a Flash beginner and followed a tutorial: http://www.webwasp.co.uk/tutorials/018/tutorial.php ... to learn how to make a "live paint/draw" effect. I didn't realize  that if I made something in AS2, I wouldn't be able to embed it (and  have it work) into my root AS3 file, where I've got a bunch of other  stuff going on. I've tried following tips on how to change AS2 code to  AS3, but it just doesn't work. I know it's simple code, and that some  genius out there can figure it out, but I'm at a loss. Please help!

Here's the AS2 code:

_root.createEmptyMovieClip("myLine", 0);

_root.onMouseDown = function() {
   myLine.moveTo(_xmouse, _ymouse);
   ranWidth = Math.round((Math.random() * 10)+2);
   myLine.lineStyle(ranWidth, 0xff0000, 100);
   _root.onMouseMove = function() {
      myLine.lineTo(_xmouse, _ymouse);
   }
}

_root.onMouseUp = function() {
   _root.onMouseMove = noLine;
}

Thanks in advance!

Signed,

Nicolle

Flash Desperado

This topic has been closed for replies.

1 reply

Inspiring
March 25, 2011

Considering the code is on timeline:

var myLine:Sprite = new Sprite();
addChild(myLine);
var g:Graphics = myLine.graphics;

addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);

function onMouseDown(e:MouseEvent):void {
     var ranWidth:Number = Math.round((Math.random() * 10) + 2);
     g.clear();
     g.lineStyle(ranWidth, 0xFF0000, 1);
     addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
     addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
}

function onMouseMove(e:MouseEvent):void {
     g.lineTo(mouseX, mouseY);
}

function onMouseUp(e:MouseEvent):void {
     removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
     removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
}