forked from: draw demo
// forked from mash's draw demo
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
public class DrawDemo extends Sprite {
private var is_clicked :Boolean = false;
private var lastx :Number = 0;
private var lasty :Number = 0;
public function DrawDemo() {
var line :int = 5;
var color :uint = 1;
graphics.lineStyle( 1, 0xEA564F );
stage.addEventListener( MouseEvent.MOUSE_DOWN, function(e :MouseEvent) :void {
is_clicked = true;
lastx = mouseX;
lasty = mouseY;
graphics.moveTo( lastx, lasty );
color++;
graphics.lineStyle( line, color );
});
stage.addEventListener( MouseEvent.MOUSE_MOVE, function(e :MouseEvent) :void {
if ( is_clicked ) {
graphics.lineTo( mouseX, mouseY );
}
var start :Number = lastx + lasty;
lastx = mouseX;
lasty = mouseY;
var now :int = (lastx + lasty) - start;
if(now > 1){
color++;
graphics.lineStyle( line, color );
}
});
stage.addEventListener( MouseEvent.MOUSE_UP, function(e :MouseEvent) :void {
is_clicked = false;
});
}
}
}