Scribble Class

December 22nd, 2007

I am sure by now you know about the NapkinNotebook website I did for Euro RSCG but what I haven’t had a chance to show you yet is some of the code behind how it works.

Although the final scribble class looks a little different, this is the first prototype Myles created for me.

package{
       
        import flash.display.Sprite;
        import flash.filters.DropShadowFilter;
        import flash.events.MouseEvent;
       
        public class DrawLines extends Sprite{
               
                private var container:Sprite;
                private var canvas:Sprite;
               
                public function DrawLines(){
                        drawCanvas();
                }              
               
                private function drawCanvas():void{
                        container = new Sprite();
                        container.graphics.beginFill(0xff0066,0);
                        container.graphics.lineTo(this.stage.stageWidth,0);
                        container.graphics.lineTo(this.stage.stageWidth,this.stage.stageHeight);
                        container.graphics.lineTo(0,this.stage.stageHeight);
                        container.graphics.lineTo(0,0);
                        container.graphics.endFill();
                        addChild(container);
                        canvas = new Sprite();
                        canvas.filters = [new DropShadowFilter(0,45,0,1,5,5,3)];
                        addChild(canvas);
                        container.addEventListener(MouseEvent.MOUSE_DOWN, downHandler);
                }
               
                private function downHandler(event:MouseEvent):void{
                        container.addEventListener(MouseEvent.MOUSE_MOVE, startDraw);
                        container.addEventListener(MouseEvent.MOUSE_UP, stopDraw);
                        canvas.addEventListener(MouseEvent.MOUSE_UP, stopDraw);
                        canvas.graphics.lineStyle(1,0,1);
                        canvas.graphics.moveTo(container.mouseX,container.mouseY);
                }
                private function startDraw(event:MouseEvent):void{
                        canvas.graphics.lineTo(container.mouseX,container.mouseY);
                }
                private function stopDraw(event:MouseEvent):void{
                        container.removeEventListener(MouseEvent.MOUSE_MOVE, startDraw);
                }
               
        }
       
}

Also, don’t forget to visit the site, send a sketch to a friend, and buy a Napkin Notebook for yourself or a friend.

Leave a Reply