forked from: Drawing API and Mouse Events
/////Class by swfgeek
///// http://www.swfgeek.net
// forked from swfgeek's Drawing API and Mouse Events
/*
/////Class by swfgeek
///// http://www.swfgeek.net
*/
package {
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.events.MouseEvent;
import flash.geom.Matrix;
import com.adobe.viewsource.ViewSource;
[SWF(backgroundColor="0x000000",frameRate="31")]
public class DrawingAPI extends Sprite
{
private var sprite:Sprite;
private var holder:Sprite;
private var myCircle:Sprite;
private var fillType:String;
private var colors:Array;
private var alphas:Array;
private var ratios:Array;
private var matr:Matrix;
private var spreadMethod:String;
private var focalPointRatio:Number;
public function DrawingAPI()
{
init();
}
private function init():void
{
ViewSource.addMenuItem(this, "srcview/index.html");
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(MouseEvent.MOUSE_DOWN,prepareToDraw);
}
public function prepareToDraw(event:MouseEvent):void
{
stage.addEventListener(MouseEvent.MOUSE_MOVE,drawGraphics);
stage.addEventListener(MouseEvent.MOUSE_UP,stopDrawing);
}
public function drawGraphics(event:MouseEvent):void
{
fillType = GradientType.RADIAL;
colors = [0xFFFFFF, Math.random()*0xFFFFFF];
alphas = [1, 1];
ratios = [0x37, 0xFF];
matr= new Matrix();
matr.createGradientBox(100, 100, Math.random()*360, -40, 0);
spreadMethod = SpreadMethod.PAD;
focalPointRatio = 1;
holder = new Sprite();
addChild(holder);
myCircle = new Sprite();
myCircle.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr,spreadMethod);
myCircle.graphics.drawCircle(0,0,40);
myCircle.graphics.endFill();
holder.addChild(myCircle);
holder.x = mouseX;
holder.y = mouseY;
holder.scaleX = holder.scaleY = Math.random()*2+0.5;
holder.rotation = Math.random()*360;
holder.alpha = Math.random()+0.7;
}
public function stopDrawing(event:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE,drawGraphics)
}
}
}