Drawing App
Just hit the spacebar to clear!
package
{
[SWF(width = 465, height = 465, backgroundColor = 0x000000, frameRate = 60)]
import flash.display.Sprite;
import flash.display.Graphics;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class FlashTest extends Sprite
{
private var g:Graphics = null;
private var drawing:Boolean = false;
public function FlashTest()
{
g = this.graphics;
stage.addEventListener(MouseEvent.MOUSE_MOVE,draw);
stage.addEventListener(MouseEvent.MOUSE_DOWN,startDrawing);
stage.addEventListener(MouseEvent.MOUSE_UP,stopDrawing);
stage.addEventListener(KeyboardEvent.KEY_DOWN,clearDrawing);
}
public function draw(e:MouseEvent):void
{
if(drawing)
{
g.lineStyle(1,0x000000);
g.lineTo(mouseX,mouseY);
}
}
public function startDrawing(e:MouseEvent):void
{
if(!drawing)
{
g.moveTo(mouseX,mouseY);
drawing = true;
}
}
public function stopDrawing(e:MouseEvent):void
{
if(drawing)
{
drawing = false;
}
}
public function clearDrawing(e:KeyboardEvent):void
{
if(e.keyCode == Keyboard.SPACE)
{
g.clear();
}
}
}
}