forked from: flash on 2012-11-15
forked from flash on 2012-11-15 (diff: 29)
ActionScript3 source code
/**
* Copyright ysissy ( http://wonderfl.net/user/ysissy )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/c5Nu
*/
// forked from eff_01's flash on 2012-11-15
package {
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Sprite;
public class syBrush extends Sprite {
public function syBrush() {
var drawpad : Sprite = new Sprite();
addChild(drawpad);
// Capturing Mouse Cursor Coordinate
stage.addEventListener(MouseEvent.MOUSE_DOWN,doMouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP,doMouseUp);
stage.addEventListener(MouseEvent.MOUSE_MOVE,doMouseMove);
var drawflag : Boolean = false;
var linedata : Array = new Array();
// Start to add coordinate into array when mouse is down
function doMouseDown(e:MouseEvent):void{
drawflag = true;
linedata = new Array(); // To Create multidimensional arrays Perhaps??? Or Initialize array??
linedata.push ([mouseX,mouseY]);
}
// Add coordinate to array when mouse moves
function doMouseMove(e:MouseEvent):void{
if(drawflag) {
linedata.push([mouseX,mouseY]);
}
}
// Stop to add coordinate when mouse is up
function doMouseUp(e:MouseEvent):void{
drawflag = false;
}
// Draw line during every frames
drawpad.addEventListener(Event.ENTER_FRAME,doEnter);
function doEnter(e:Event) : void {
var wx:Number;
var wy:Number;
// when array starts to fill in (equal to when mouse clicked)
if (0 < linedata.length) {
// Clean at once : only draw one stroke in one time
//drawpad.graphics.clear();
//Draw with Red Line
drawpad.graphics.lineStyle( 1, 0xFF0000 );
// Position when mouse click
wx = linedata[0][0];
wy = linedata[0][1];
// And Ready for Drawing ; Move Pen to clicked coordinate
drawpad.graphics.moveTo(wx,wy);
// Draw
for(var i:int = 1; i < linedata.length; i++) {
wx = linedata[i][0]; // First value i = 1 means "After Click"
wy = linedata[i][1];
drawpad.graphics.lineTo(wx,wy);
}
}
}
}
}
}