PDA

View Full Version : help draw line



ssubham
June 16th, 2009, 03:28 PM
Hi guys,

need help to draw a line on mouse movement, not the static line.

I am attaching a sample which is 90 degree bounded as it has been given in animation, I want to make this or such type through mouse movement.


I hope I can get a help from the looking guys.

thanks
ssubham

BoppreH
June 16th, 2009, 03:38 PM
var mcLines:MovieClip = new MovieClip() // creates our holder
mcLines.graphics.lineStyle(1) // set line thickness to 1
mcLines.graphics.moveTo(mouseX, mouseY) // moves the "pointer" to the mouse. This pointer is what will draw the lines later

addChild(mcLines)

stage.addEventListener(MouseEvent.MOUSE_MOVE, drawLine) // updates the lines every time the mouse moves

function drawLine(e:MouseEvent) {
mcLines.graphics.lineTo(mouseX, mouseY) // this is the line that actually draws the line to the current cursor position
}

To stop, just remove the event listener:

stage.removeEventListener(MouseEvent.MOUSE_MOVE, drawLine)

You can check other methods and line styles in the documentation page: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Graphics.html