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

そうめんでParticle

Get Adobe Flash player
by matsu4512 08 May 2009
    Embed
package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	
	import org.libspark.thread.EnterFrameThreadExecutor;
	import org.libspark.thread.Thread;

	[SWF(backgroundColor="0x000000", width=512, height=512)]
	
	public class Thread_Particle extends Sprite
	{
		
		public function Thread_Particle()
		{
			if(stage)
				init();
			else
				addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init():void{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			if(!Thread.isReady){
				Thread.initialize(new EnterFrameThreadExecutor());
				var myThread:MyThread = new MyThread(this);
				myThread.start();
			}
		}
	}
}
	import org.libspark.thread.Thread;
	import flash.display.BitmapData;
	import __AS3__.vec.Vector;
	import flash.events.MouseEvent;
	import flash.display.InteractiveObject;
	import flash.display.DisplayObject;
	import flash.display.Stage;
	import flash.display.Sprite;
	import flash.display.Bitmap;
	import flash.filters.GradientBevelFilter;
	import flash.display.Shape;
	import flash.display.BlendMode;
	import org.libspark.thread.threads.tweener.TweenerThread;
	import flash.geom.Point;
	import flash.filters.BlurFilter;
	

class MyThread extends Thread{
	private var sp:Sprite;
	private var w:Number;
	private var h:Number;
	private var particles:Vector.<Particle>;
	
	public function MyThread(sp:Sprite){
		this.sp = sp;
		w = sp.stage.stageWidth;
		h = sp.stage.stageHeight;
		particles = new Vector.<Particle>();
	}
	
	override protected function run():void{
		event(sp.stage, MouseEvent.MOUSE_DOWN, mouseDown);
		particles = particles.filter(func);
	}
	
	private function mouseDown(e:MouseEvent=null):void{
		event(sp.stage, MouseEvent.MOUSE_UP, mouseUp);
		var p:Particle = new Particle();
		p.tox = p.x = Math.random() * w;
		p.toy = p.y = Math.random() * h;
		p.toz = p.z = Math.random()  * 200 -100;
		sp.addChild(p);
		particles.push(p);
		var tween:Thread = new TweenerThread(p, {x:sp.mouseX, y:sp.mouseY, z:0, alpha:1, time:Math.random()*3+0.1});
		tween.start();
		next(mouseDown);
	}
	
	private function mouseUp(e:MouseEvent=null):void{
		var tween:Thread;
		for each(var p:Particle in particles){
			tween = new TweenerThread(p, {x:p.tox, y:p.toy, z:p.toz, alpha:0, time:Math.random()*2+0.1});
			tween.start();
		}
		next(run);
	}
	
	private function func(item:Particle, index:int, vec:Vector.<Particle>):Boolean{
       	if(item.alpha <= 0){
       		return false;
       	}
       	else 
       		return true;
	}
}

class Particle extends Shape{
	public var tox:Number;
	public var toy:Number;
	public var toz:Number;
	
	public function Particle(){
		
		this.alpha = Math.random()*0.5;
		this.blendMode = BlendMode.ADD;
		this.filters = [new BlurFilter(10, 10, 1)]; 
		draw();
	}
	
	private function draw():void{
		graphics.beginFill(0xFF0000 + 0x00FFFF*Math.random());
		graphics.drawCircle(0, 0, Math.random()*10+1);
		graphics.endFill();
	}
}