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

LightFire

//////////////////////////////////////////////////////////////////////////////
[AS3.0] 燃える火・きらめく星・流れる水
http://www.project-nya.jp/modules/weblog/details.php?blog_id=1047
//////////////////////////////////////////////////////////////////////////////
Get Adobe Flash player
by ProjectNya 20 May 2010
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/nqGx
 */

////////////////////////////////////////////////////////////////////////////////
//  [AS3.0] 燃える火・きらめく星・流れる水
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1047
////////////////////////////////////////////////////////////////////////////////

package {

	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	//import net.hires.debug.Stats;

	[SWF(backgroundColor="#000000", width="465", height="465", frameRate="30")]

	public class Main extends Sprite {
		private var fire:LightFire;
		private var playing:Boolean = true;

		public function Main() {
			Wonderfl.capture_delay(4);
			init();
			//addChild(new Stats());
		}

		private function init():void {
			graphics.beginFill(0x000000);
			graphics.drawRect(0, 0, 465, 465);
			graphics.endFill();
			fire = new LightFire();
			addChild(fire);
			fire.x = 232;
			fire.y = 252;
			fire.init(4, 80);
			fire.color = [0xFF0000, 0xFF9900, 0xFFFF00];
			fire.start();
			stage.addEventListener(MouseEvent.CLICK, click, false, 0, true);
		}
		private function click(evt:MouseEvent):void {
			playing = !playing;
			if (playing) {
				fire.start();
			} else {
				fire.stop();
			}
		}

	}

}


import flash.display.Sprite;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.geom.Rectangle;
import flash.geom.ColorTransform;
import flash.display.BlendMode;

class LightFire extends Sprite {
	private static var ids:Array = [0, 0, 0, 0, 0, 1, 1, 2, 3];
	private var colors:Array;
	private var unit:uint = 1;
	private var range:uint = 100;
	private var radian:Number = Math.PI/180;

	public function LightFire() {
		mouseChildren = false;
	}

	public function init(n:uint, r:uint):void {
		unit = n;
		range = r;
	}
	public function set color(list:Array):void {
		colors = list;
		colors.push(0xFFFFFF);
	}
	public function start():void {
		addEventListener(Event.ENTER_FRAME, createLight, false, 0, true);
	}
	public function stop():void {
		removeEventListener(Event.ENTER_FRAME, createLight);
	}
	private function createLight(evt:Event):void {
		for (var n:uint = 0; n < unit; n++) {
			create();
		}
	}
	private function create():void {
		var fire:ParticleFire = new ParticleFire();
		addChild(fire);
		var radius:Number = Math.random()*range;
		var angle:Number = Math.random()*360;
		var px:Number = radius*Math.cos(angle*radian);
		var py:Number = radius*Math.sin(angle*radian);
		fire.x = px;
		fire.y = py;
		var colorTrans:ColorTransform = new ColorTransform(0, 0, 0, 1, 0, 0, 0, 0);
		var id:uint = ids[Math.floor(Math.random()*(ids.length+1))];
		colorTrans.color = colors[id];
		fire.transform.colorTransform = colorTrans;
		fire.blendMode = BlendMode.ADD;
	}

}


import flash.display.Sprite;
import flash.display.Shape;
import flash.geom.Matrix;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.InterpolationMethod;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.tweens.ITween;
import org.libspark.betweenas3.easing.Linear;
import org.libspark.betweenas3.events.TweenEvent;

class ParticleFire extends Sprite {
	private var base:Shape;
	private static var _width:uint = 40;
	private static var _height:uint = 80;
	private static var yOffset:int = -10;
	private static var targetPos:int = -60;
	private var count:uint = 0;
	private static var bColor:uint = 0xFFFFFF;

	public function ParticleFire() {
		draw();
		init();
	}

	private function init():void {
		var itween:ITween = BetweenAS3.to(base, {y: targetPos, alpha: 0}, 0.6, Linear.easeNone);
		itween.addEventListener(TweenEvent.UPDATE, blink, false, 0, true);
		itween.addEventListener(TweenEvent.COMPLETE, complete, false, 0, true);
		itween.play();
	}
	private function blink(evt:TweenEvent):void {
		if (count%4 < 2) {
			visible = true;
		} else {
			visible = false;
		}
		count ++;
	}
	private function complete(evt:TweenEvent):void {
		evt.target.removeEventListener(TweenEvent.UPDATE, blink);
		evt.target.removeEventListener(TweenEvent.COMPLETE, complete);
		parent.removeChild(this);
	}
	private function draw():void {
		base = new Shape();
		addChild(base);
		var colors:Array = [bColor, bColor];
		var alphas:Array = [1, 0];
		var ratios:Array = [0, 255];
		var matrix:Matrix = new Matrix();
		matrix.createGradientBox(_width, _height, 0, -_width*0.5, -_height*0.5+yOffset);
		base.graphics.beginGradientFill(GradientType.RADIAL, colors, alphas, ratios, matrix, SpreadMethod.PAD, InterpolationMethod.RGB, 0);
		base.graphics.drawEllipse(-_width*0.5, -_height*0.5+yOffset, _width, _height);
		base.graphics.endFill();
	}

}