Posted By

swfgeek on 05/19/08


Tagged

drawingAPI actionscript3 MouseEvents swfgeek


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

THEPWN3R


DrawingAPI


 / Published in: ActionScript 3
 

  1. /*
  2. /////---- Class by Dave Ga?mez (.swfgeek) 24-February-2008 http://www.swfgeek.net----\\\\\\
  3. ///---- Original Example by: Sorin Haidan in his Draw Custom shapes with ActionScript 3.0. Tutorial ----\\\
  4. ///---- Found on his blog http://biochimistu.blogspot.com/ ---- \\\
  5. */
  6.  
  7. package {
  8.  
  9. import flash.display.GradientType;
  10. import flash.display.SpreadMethod;
  11. import flash.display.Sprite;
  12. import flash.display.StageScaleMode;
  13. import flash.display.StageAlign;
  14. import flash.events.MouseEvent;
  15. import flash.geom.Matrix;
  16. import com.adobe.viewsource.ViewSource;
  17.  
  18. [SWF(backgroundColor="0x000000",frameRate="31")]
  19.  
  20. public class DrawingAPI extends Sprite
  21. {
  22. private var sprite:Sprite;
  23. private var holder:Sprite;
  24. private var myCircle:Sprite;
  25. private var fillType:String;
  26. private var colors:Array;
  27. private var alphas:Array;
  28. private var ratios:Array;
  29. private var matr:Matrix;
  30. private var spreadMethod:String;
  31. private var focalPointRatio:Number;
  32.  
  33. public function DrawingAPI()
  34. {
  35. init();
  36. }
  37.  
  38. private function init():void
  39. {
  40. ViewSource.addMenuItem(this, "srcview/index.html");
  41. stage.scaleMode = StageScaleMode.NO_SCALE;
  42. stage.align = StageAlign.TOP_LEFT;
  43. stage.addEventListener(MouseEvent.MOUSE_DOWN,prepareToDraw);
  44.  
  45. }
  46.  
  47. public function prepareToDraw(event:MouseEvent):void
  48. {
  49. stage.addEventListener(MouseEvent.MOUSE_MOVE,drawGraphics);
  50. stage.addEventListener(MouseEvent.MOUSE_UP,stopDrawing);
  51.  
  52. }
  53.  
  54. public function drawGraphics(event:MouseEvent):void
  55. {
  56. fillType = GradientType.RADIAL;
  57. colors = [0xFFFFFF, Math.random()*0xFFFFFF];
  58. alphas = [1, 1];
  59. ratios = [0x37, 0xFF];
  60. matr= new Matrix();
  61. matr.createGradientBox(100, 100, Math.random()*360, -40, 0);
  62. spreadMethod = SpreadMethod.PAD;
  63. focalPointRatio = 1;
  64. holder = new Sprite();
  65. addChild(holder);
  66. myCircle = new Sprite();
  67. myCircle.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr,spreadMethod);
  68. myCircle.graphics.drawCircle(0,0,40);
  69. myCircle.graphics.endFill();
  70. holder.addChild(myCircle);
  71. holder.x = mouseX;
  72. holder.y = mouseY;
  73. holder.scaleX = holder.scaleY = Math.random()*2+0.5;
  74. holder.rotation = Math.random()*360;
  75. holder.alpha = Math.random()+0.7;
  76. }
  77.  
  78. public function stopDrawing(event:MouseEvent):void
  79. {
  80. stage.removeEventListener(MouseEvent.MOUSE_MOVE,drawGraphics)
  81. }
  82. }
  83. }

Report this snippet  

You need to login to post a comment.