In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Light Explosion (forked from: Blur Circle)

Dennis Wilson http://www.abakia.de/
// forked from ll_koba_ll's Blur Circle
// write as3 code here..

package {
        // Dennis Wilson http://www.abakia.de/

	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.text.TextField;	

	[SWF(frameRate="75", backgroundColor="#000000")]

        public class LightExplosion extends Sprite
        {
            public const MAX_W : uint = 500;
            public const MAX_H : uint = 500;
            public const HALF_MAX_W : uint = MAX_W/2;
            public const HALF_MAX_H : uint = MAX_H/2;

            public const MAX_PARTICLES : uint = 100;
            public const RADIUS : uint = 200;
            public const IMPLODE_SPEED : uint = 20;
            public const EXPLODE_SPEED : uint = 10;
            public const PI_DIV_180 : Number = Math.PI/180;
            
            public const CLICK_INTERVAL : uint = 180;

            public var frame: uint = 0;
            public var next_click: uint=0;

            public var blur:BlurFilter;
            public var container:Sprite;
            public var bmpd:BitmapData;
            public var tf:TextField;
            public var particles:Array = [];

            public var speed : Number = EXPLODE_SPEED;

            public function LightExplosion()
            {
                stage.scaleMode = StageScaleMode.NO_SCALE;
                stage.align = StageAlign.TOP_LEFT;
                stage.quality = StageQuality.LOW;            
                init();
                addEventListener(Event.ENTER_FRAME, update);
                next_click = frame + 100;
            }

/* Helper */

            private function init():void
            {
                blur = new BlurFilter(5,5);            
                bmpd = new BitmapData(MAX_W, MAX_H, true, 0x00ffffff);
                container = new Sprite();

                var bitmap:Sprite =  new Sprite();
                bitmap.addChild(new Bitmap(bmpd));
                bitmap.mouseEnabled = true;
                bitmap.buttonMode = true;
                bitmap.useHandCursor = true;
                bitmap.addEventListener(MouseEvent.CLICK, onClick);
                addChild(bitmap);
            
                spawnParticles();
            
                tf = new TextField();
                tf.text = "usually click triggered :-(";
                tf.width = 160;
                tf.x = 10;
                tf.y = 10;
                tf.blendMode = BlendMode.INVERT;
                addChild(tf);
            }

            private function spawnParticles() : void {
                var p : Particle;
                for(var i:int=0; i < MAX_PARTICLES; i++) {
                    p = new Particle;
		    p.x = p.x_to = HALF_MAX_W;
		    p.y = p.y_to = HALF_MAX_H;
                
                    p.blendMode = BlendMode.ADD;
                    p.alpha = 0.5;
                    container.addChild(p); 
                    particles[particles.length] = p;
                }
            }
        
/* Events */		

            private function onClick(event : MouseEvent) : void {
                trace('reached');
                for each(var p:Particle in particles) {
                    if(p.x_to != HALF_MAX_W) {
                        p.x_to = HALF_MAX_W;
                        p.y_to = HALF_MAX_H;
                        speed = IMPLODE_SPEED;
                    }
                    else {
                        p.x_to = HALF_MAX_W + Math.sin(Math.random()*180) * (Math.random() * RADIUS);
                        p.y_to = HALF_MAX_H + Math.sin(Math.random()*180) * (Math.random() * RADIUS);
                        speed = EXPLODE_SPEED;
                    }
                }
            }

            private function update(e:Event = null):void
            {
        	frame++;
        
                //WORKAROUND: simulate clicking.
                if(frame > next_click) {
                    onClick(null);
                    next_click = frame + Math.floor(Math.random()*CLICK_INTERVAL);
                }
        	
                //move
                var j:Number = 0;
        	    for each(var p:Particle in particles) {
                    p.x = p.x + (p.x_to - p.x)/speed; 
                    p.y = p.y + (p.y_to - p.y)/speed;
                
                    j = (frame + p.shift) * PI_DIV_180;
                    p.alpha = 0.5 + Math.sin(j)* 0.5;
                    p.scaleX = 1 + Math.sin(j) * 0.5;
                    p.scaleY = p.scaleX;
                }

                // draw
                bmpd.draw(container, null, null, BlendMode.ADD);
                for(var i:uint=0; i < 3; i++) {        	
                    bmpd.applyFilter(bmpd, bmpd.rect, new Point(), blur);
                }
                bmpd.draw(container, null, null, BlendMode.ADD);
	    }
	}
}


    import flash.display.Sprite;
    
    class Particle extends Sprite{
       public static const COLORS:Array = [0xbb1111, 0x11bb11,0x1111bb];

       public var x_to:Number = 0;
       public var y_to:Number = 0;
       
       public var color:uint=0;
       public var shift:Number = 0;
       public var size:Number = 0;
       
       public function Particle() {
   	    color = COLORS[Math.round(Math.random()*COLORS.length-1)];
            shift = Math.random()*999;
            
            graphics.beginFill(color);
            graphics.drawRect(-2, -2, 4,4);
            graphics.endFill();
        }
    }