emitting laser orbs
/**
* Copyright Jacky.Riawan ( http://wonderfl.net/user/Jacky.Riawan )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/jCJj
*/
package {
import flash.geom.Point;
import flash.filters.BlurFilter;
import flash.events.Event;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.MovieClip;
import flash.display.Sprite;
[SWF(backgroundColor="#000000",width="465", height="465", frameRate="60")]
public class FlashTest extends Sprite {
private var mySprite:Sprite
private var topSprite:Sprite
private var bitmapData:BitmapData
private var blur:BlurFilter
private var timedDel:int=0
public function FlashTest() {
// write as3 code here..
mySprite=new Sprite()
topSprite=new Sprite()
blur=new BlurFilter();
addChild(mySprite);
for(var i:int=0;i<100;i++){
var myOrb:orb=new orb(Math.random()*465,Math.random()*465,topSprite);
mySprite.addChild(myOrb);
}
bitmapData=new BitmapData(465,465,true,0x000000);
var bitmap:Bitmap=new Bitmap(bitmapData);
addChild(bitmap)
addChild(topSprite)
addEventListener(Event.ENTER_FRAME,doStuffs)
}
private function doStuffs(e:Event):void{
timedDel++
if(timedDel%3==0){
topSprite.graphics.clear();
}
bitmapData.draw(mySprite);
bitmapData.applyFilter(bitmapData,bitmapData.rect,new Point(0,0),blur);
}
}
}
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.Sprite;
class orb extends MovieClip{
private var drawSprite:Sprite
public function orb(posx:Number,posy:Number,tgtSprite:Sprite){
x=posx
y=posy
drawSprite=tgtSprite
this.addEventListener(Event.ENTER_FRAME,render)
}
private function render(e:Event):void{
var range:int=Math.pow(e.target.x-e.target.root.mouseX,2)+Math.pow(e.target.y-e.target.root.mouseY,2)
this.graphics.clear()
if(range<10000){
var lineAlpha:Number=1-(range/10000);
//circle
this.graphics.lineStyle(1,0xFFFFFF,lineAlpha);
this.graphics.drawCircle(0,0,5*lineAlpha);
//the leg
e.target.drawSprite.graphics.lineStyle(1,0xFFFFFF,lineAlpha)
e.target.drawSprite.graphics.moveTo(e.target.x,e.target.y);
e.target.drawSprite.graphics.lineTo(e.target.root.mouseX,e.target.root.mouseY);
}
}
}