Forked from: esabear's GradientFill center follow with mouse diff:6 forked from: GradientFill center follow with mouse makisho forked:0favorite:1lines:40license : MIT License modified : 2011-05-27 05:53:26 Embed Tweet // forked from esabear's GradientFill center follow with mouse package { import flash.geom.Point; import flash.geom.Matrix; import flash.display.Sprite; import flash.events.MouseEvent; import flash.display.GradientType; import flash.display.SpreadMethod; import flash.display.InterpolationMethod; public class FlashTest extends Sprite { public var fillColor:int = 0x0000FF; public function FlashTest() { // write as3 code here.. stage.addEventListener (MouseEvent.MOUSE_MOVE, redraw); stage.addEventListener (MouseEvent.CLICK, changeColor); changeColor (); redraw (); } private function redraw (e:MouseEvent=null):void { var mouse:Point = new Point (mouseX, mouseY); var center:Point = new Point (stage.stageWidth * 0.5, stage.stageHeight * 0.5); var matrix:Matrix = new Matrix(); matrix.createGradientBox (stage.stageWidth*2 , stage.stageHeight *2 , Math.atan2 (mouseY-center.y, mouseX-center.x), -center.x, -center.y); graphics.clear (); graphics.beginGradientFill ( GradientType.RADIAL, [fillColor, 0x00FF00, 0xCCCCCC, 0x000000], [1, 1,1,1], [0x00, 0xFF,0x00, 0xFF], matrix, SpreadMethod.PAD, InterpolationMethod.RGB, Point.distance(mouse, center) * stage.stageWidth ); graphics.drawRect (0, 0, stage.stageWidth, stage.stageHeight); graphics.endFill (); } private function changeColor (e:MouseEvent=null):void { fillColor = 0xFFFFFF * Math.random(); } } } Code Fullscreen Preview Fullscreen xor InterpolationMethod.RGB Matrix MouseEvent.MOUSE_MOVE createGradientBox MouseEvent Math.atan2 MouseEvent.CLICK Math.random int