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

20,000 particles with BetweenAS3

Get Adobe Flash player
by beinteractive 08 May 2009
  • Related works: 6
  • Talk

    joo at 25 Jul 2009 10:29
    BeTweenAS3 を PV3Dとともに具現した例題たちはどうしてずっと下のような 間違いが出るか知れないです. 一日中検索して見たが頭だけ痛いですね手伝ってください TypeError: Error #1009: null 客体参照の速成やメソッドにアクセスすることができません. at org.libspark.betweenas3.targets.single.display::DisplayObjectTweenTarget/setSourceValue() at org.libspark.betweenas3.factories::StandardSingleTweenTargetFactory/create() at org.libspark.betweenas3::BetweenAS3$/tween() at Main()
    beinteractive at 13 Aug 2009 14:33
    Thank you for your bug report! I'm sorry. This issue was fixed in the new version. Please try.

    Tags

    Embed
package
{
	import com.flashdynamix.utils.SWFProfiler;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.PixelSnapping;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageQuality;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.geom.ColorTransform;
	import flash.geom.Point;
	import org.libspark.betweenas3.BetweenAS3;
	import org.libspark.betweenas3.easing.Back;
	import org.libspark.betweenas3.easing.Quart;
	import org.libspark.betweenas3.tweens.ITween;
	
	public class ParticleBetween extends Sprite
	{
		private static const NUM_PARTICLES:uint = 20000;
		private static const FADE:ColorTransform = new ColorTransform(1, 1, 1, 1, -32, -16, -16);
		
		public function ParticleBetween()
		{
			setupParticles();
			setupScreen();
			setupStage();
			
			SWFProfiler.init(this);
			
			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}
		
		private var _bitmapData:BitmapData;
		private var _bitmap:Bitmap;
		private var _particles:Particle;
		
		private function setupParticles():void
		{
			var prev:Particle = _particles = new Particle();
			var p:Particle = null;
			var a:Number, dx:Number, dy:Number;
			var t:ITween;
			var i:int = NUM_PARTICLES;
			while (--i >= 0) {
				
				a = Math.random() * Math.PI * 2;
				dx = Math.cos(a) * 465 + 465 / 2;
				dy = Math.sin(a) * 465 + 465 / 2;
				
				p = new Particle();
				p.p.x = 465 / 2;
				p.p.y = 465 / 2;
				
				t = BetweenAS3.tween(p.p, {x: dx, y: dy}, null, 1.5 + Math.random() * 4.5, Quart.easeIn);
				t.stopOnComplete = false;
				t.play();
				
				prev.next = p;
				prev = p;
			}
		}
		
		private function setupScreen():void
		{
			_bitmapData = new BitmapData(465, 465, false, 0x000000);
			_bitmap = addChild(new Bitmap(_bitmapData, PixelSnapping.NEVER, false)) as Bitmap;
		}
		
		private function setupStage():void
		{
			stage.frameRate = 60;
			stage.quality = StageQuality.LOW;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			stage.addEventListener(Event.RESIZE, resizeHandler);
			resizeHandler(null);
		}
		
		private function resizeHandler(e:Event):void
		{
			_bitmap.x = Math.floor((stage.stageWidth - 465) / 2);
			_bitmap.y = Math.floor((stage.stageHeight - 465) / 2);
		}
		
		private function enterFrameHandler(e:Event):void
		{
			var bitmapData:BitmapData = _bitmapData;
			
			bitmapData.lock();
			bitmapData.colorTransform(_bitmapData.rect, FADE);
			
			var p:Particle = _particles;
			var pos:Point;
			while ((p = p.next) != null) {
				pos = p.p;
				bitmapData.setPixel(pos.x >> 0, pos.y >> 0, 0xffffff);
			}
			
			bitmapData.unlock();
		}
	}
}

import flash.geom.Point;

internal class Particle
{
	public var p:Point = new Point();
	public var next:Particle;
}