Advertisement
wewgu

Paint Drawing

Oct 6th, 2017
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import flash.display.Sprite;
  2. import flash.events.MouseEvent;
  3.  
  4. var drawing:Boolean = false;
  5. var erasering:Boolean = false;
  6.  
  7. var canvas:Sprite = new Sprite();
  8. canvas.graphics.beginFill(0xffffff);
  9. canvas.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
  10. canvas.graphics.endFill();
  11. addChildAt(canvas, 0);
  12.  
  13. pencil_mc.addEventListener(MouseEvent.CLICK, pencil);
  14.  
  15. function pencil(event:MouseEvent)
  16. {
  17.     if(!drawing)
  18.     {
  19.         drawing = true;
  20.         erasering = false;
  21.         pencil_mc.gotoAndStop(2);
  22.         eraser_mc.gotoAndStop(1);
  23.     } else
  24.     {
  25.         drawing = false;
  26.         pencil_mc.gotoAndStop(1);
  27.     }
  28. }
  29.  
  30. eraser_mc.addEventListener(MouseEvent.CLICK, eraser);
  31.  
  32. function eraser(event:MouseEvent)
  33. {
  34.     if(!erasering)
  35.     {
  36.         erasering = true;
  37.         drawing = false;
  38.         eraser_mc.gotoAndStop(2);
  39.         pencil_mc.gotoAndStop(1);
  40.     } else
  41.     {
  42.         erasering = false;
  43.         eraser_mc.gotoAndStop(1);
  44.     }
  45. }
  46.  
  47. canvas.addEventListener(MouseEvent.MOUSE_DOWN, startDraw);
  48.  
  49. function startDraw(event:MouseEvent)
  50. {
  51.     if(drawing)
  52.     {
  53.         canvas.graphics.lineStyle(2, paletcolor.selectedColor);
  54.         canvas.graphics.moveTo(mouseX, mouseY);
  55.         canvas.addEventListener(MouseEvent.MOUSE_MOVE, movePen);
  56.         canvas.removeEventListener(MouseEvent.MOUSE_MOVE, moveEraser);
  57.     } else if(erasering)
  58.     {
  59.         canvas.graphics.lineStyle(70, 0xffffff);
  60.         canvas.graphics.moveTo(mouseX, mouseY);
  61.         canvas.addEventListener(MouseEvent.MOUSE_MOVE, moveEraser);
  62.         canvas.removeEventListener(MouseEvent.MOUSE_MOVE, movePen);
  63.     }
  64. }
  65.  
  66. function movePen(event:MouseEvent)
  67. {
  68.     canvas.graphics.lineTo(mouseX, mouseY);
  69. }
  70.  
  71. function moveEraser(event:MouseEvent)
  72. {
  73.     canvas.graphics.lineTo(mouseX, mouseY);
  74. }
  75.  
  76. canvas.addEventListener(MouseEvent.MOUSE_UP, stopDraw);
  77.  
  78. function stopDraw(event:MouseEvent)
  79. {
  80.     if(drawing)
  81.     {
  82.         canvas.graphics.lineTo(mouseX, mouseY);
  83.         canvas.removeEventListener(MouseEvent.MOUSE_MOVE, movePen);
  84.     } else if(erasering)
  85.     {
  86.         canvas.graphics.lineTo(mouseX, mouseY);
  87.         canvas.removeEventListener(MouseEvent.MOUSE_MOVE, moveEraser);
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement