Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- var drawing:Boolean = false;
- var erasering:Boolean = false;
- var canvas:Sprite = new Sprite();
- canvas.graphics.beginFill(0xffffff);
- canvas.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
- canvas.graphics.endFill();
- addChildAt(canvas, 0);
- pencil_mc.addEventListener(MouseEvent.CLICK, pencil);
- function pencil(event:MouseEvent)
- {
- if(!drawing)
- {
- drawing = true;
- erasering = false;
- pencil_mc.gotoAndStop(2);
- eraser_mc.gotoAndStop(1);
- } else
- {
- drawing = false;
- pencil_mc.gotoAndStop(1);
- }
- }
- eraser_mc.addEventListener(MouseEvent.CLICK, eraser);
- function eraser(event:MouseEvent)
- {
- if(!erasering)
- {
- erasering = true;
- drawing = false;
- eraser_mc.gotoAndStop(2);
- pencil_mc.gotoAndStop(1);
- } else
- {
- erasering = false;
- eraser_mc.gotoAndStop(1);
- }
- }
- canvas.addEventListener(MouseEvent.MOUSE_DOWN, startDraw);
- function startDraw(event:MouseEvent)
- {
- if(drawing)
- {
- canvas.graphics.lineStyle(2, paletcolor.selectedColor);
- canvas.graphics.moveTo(mouseX, mouseY);
- canvas.addEventListener(MouseEvent.MOUSE_MOVE, movePen);
- canvas.removeEventListener(MouseEvent.MOUSE_MOVE, moveEraser);
- } else if(erasering)
- {
- canvas.graphics.lineStyle(70, 0xffffff);
- canvas.graphics.moveTo(mouseX, mouseY);
- canvas.addEventListener(MouseEvent.MOUSE_MOVE, moveEraser);
- canvas.removeEventListener(MouseEvent.MOUSE_MOVE, movePen);
- }
- }
- function movePen(event:MouseEvent)
- {
- canvas.graphics.lineTo(mouseX, mouseY);
- }
- function moveEraser(event:MouseEvent)
- {
- canvas.graphics.lineTo(mouseX, mouseY);
- }
- canvas.addEventListener(MouseEvent.MOUSE_UP, stopDraw);
- function stopDraw(event:MouseEvent)
- {
- if(drawing)
- {
- canvas.graphics.lineTo(mouseX, mouseY);
- canvas.removeEventListener(MouseEvent.MOUSE_MOVE, movePen);
- } else if(erasering)
- {
- canvas.graphics.lineTo(mouseX, mouseY);
- canvas.removeEventListener(MouseEvent.MOUSE_MOVE, moveEraser);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement