Translate

> > Flex Pen tool (Drawing canvas)

Flex Pen tool (Drawing canvas)

Posted on Sunday, September 25, 2011 | No Comments

package
{
    import mx.containers.Canvas;

    public class LineCanvas extends Canvas
    {
        public var allowDrawing:Boolean=false;
        public var lineColor:uint = 0xFF0000;
        public var lineThickness:int = 2;

        public function LineCanvas()
        {
            super();
        }

    }
}
save this as LineCanvas.as


ad this your main app

private var lm:LineCanvas;

lm = new LineCanvas();
            canvas.addChild(lm);
            this.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
            this.addEventListener(MouseEvent.MOUSE_UP,mouseUp);
            this.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoving);


private function mouseDown(e:MouseEvent):void
        {
        lm.graphics.moveTo(e.target.mouseX, e.target.mouseY);
        lm.graphics.lineStyle(lm.lineThickness, lm.lineColor, 1, false, CapsStyle.ROUND);
        lm.allowDrawing=true;
        }

        private function mouseMoving(e:MouseEvent):void
        {
            if (lm.allowDrawing)
            {
            lm.graphics.lineTo(e.target.mouseX, e.target.mouseY);
            e.updateAfterEvent();
            }
        }


        private function mouseUp(e:MouseEvent):void
        {
            lm.allowDrawing=false;
        }

Leave a Reply

Powered by Blogger.