theBoard: movie clip, the same size as the stage. |
||
import flash.display.Shape;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.events.Event;
stop();
var myShape:Shape = new Shape();
theBoard.addChild(myShape);
stage.addEventListener(MouseEvent.MOUSE_DOWN, startToDraw);
stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
stage.addEventListener(Event.ENTER_FRAME, drawTheLine);
var coordinates:Array;
var i:int =0;
var beginToDraw :Boolean = false;
function startToDraw(e:MouseEvent){
coordinates = new Array();
coordinates.push(new Point(mouseX, mouseY));
myShape.graphics.lineStyle(4, 0xffffff);
//myShape.graphics.moveTo(mouseX, mouseY);
beginToDraw = true;
}
function drawTheLine(e:Event){
if(beginToDraw == true){
coordinates.push(new Point(mouseX, mouseY));
for(i = 0; i <coordinates.length-1; i++){
myShape.graphics.moveTo(coordinates[i].x, coordinates[i].y);
myShape.graphics.lineTo(coordinates[i+1].x, coordinates[i+1].y);
trace(coordinates[i].x + ", " + coordinates[i].y);
}
}
}
function stopDrawing(e:MouseEvent){
beginToDraw = false;
myShape.graphics.clear();
} |
||
![]() |
||