In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Drawing App

Just hit the spacebar to clear!
Get Adobe Flash player
by joeRob2468 11 Jun 2011
    Embed
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();
            }
        }
    }
}