Posted By

gfazioli on 04/03/08


Tagged

actionscript flash design 30 CS3 Sviluppo Tutorials Grafica


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

gfazioli
bumz
THEPWN3R


Paint-o-matic


 / Published in: ActionScript 3
 

URL: http://www.undolog.com/2008/02/09/paint-o-matic/

  1. import flash.events.MouseEvent;
  2. import flash.geom.Matrix;
  3. //
  4. // flag per il detect del mousedown
  5. var md:Boolean = false;
  6. //
  7. // creo una lavagna front
  8. var lvg1:Sprite = new Sprite();
  9. lvg1.graphics.lineStyle(0,0xffffff);
  10. lvg1.graphics.beginFill(0x666666);
  11. lvg1.graphics.drawRect(0,0,199,199);
  12. lvg1.graphics.endFill();
  13. addChild(lvg1);
  14. lvg1.x = lvg1.y = 30;
  15. //
  16. // creo la lavagna inclinata
  17. var lvg2:Sprite = new Sprite();
  18. lvg2.graphics.lineStyle(0,0xffffff);
  19. lvg2.graphics.beginFill(0x666666);
  20. lvg2.graphics.drawRect(0,0,199,199);
  21. lvg2.graphics.endFill();
  22. lvg2.x = 400;
  23. lvg2.y = lvg1.y;
  24. lvg2.rotation = 45;
  25. lvg2.scaleX = lvg2.scaleY = .6;
  26. addChild(lvg2);
  27. //
  28. // paint event
  29. lvg1.addEventListener (MouseEvent.MOUSE_DOWN, _onMouseDown);
  30. lvg1.addEventListener (MouseEvent.MOUSE_MOVE, _onMouseMove);
  31. lvg1.addEventListener (MouseEvent.MOUSE_UP, _onMouseUp);
  32. //
  33. function _onMouseDown (e:MouseEvent):void {
  34. trace("_onMouseDown");
  35. var c:uint = 0xffffff;
  36. e.target.graphics.lineStyle (10,c,1);
  37. lvg2.graphics.lineStyle (10,c,1);
  38. e.target.graphics.moveTo (e.localX,e.localY);
  39. lvg2.graphics.moveTo (e.localX,e.localY);
  40. md = true;
  41. }
  42. //
  43. function _onMouseUp (e:MouseEvent):void {
  44. md = false;
  45. }
  46. //
  47. function _onMouseMove (e:MouseEvent):void {
  48. trace("_onMouseMove");
  49. if (md) {
  50. e.target.graphics.lineTo (e.localX,e.localY);
  51. lvg2.graphics.lineTo (e.localX,e.localY);
  52. }
  53. }

Report this snippet  

You need to login to post a comment.