Simulating Pencil Tool in AS3



var drawing:Boolean = false;
this.graphics.lineStyle(1, 0x000000);
this.graphics.moveTo(mouseX, mouseY);
this.addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown, false, 0,true);
stage.addEventListener(MouseEvent.MOUSE_UP, onUp, false, 0, true);

function onDown(evt:MouseEvent):void
{
     drawing = true;
}
function onUp(evt:MouseEvent):void
{
     drawing = false;
}

function onLoop(evt:Event):void
{
     if (drawing)
     {
          this.graphics.lineTo(mouseX, mouseY);
     }
     else
     {
          this.graphics.moveTo(mouseX, mouseY);
     }
}

0 comments :