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

NukumiZoom 002

Get Adobe Flash player
by mtok 08 Jan 2009
    Embed
package  
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.events.ProgressEvent;
	import flash.geom.Point;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;
	import flash.text.TextField;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.text.TextFormat;
	import flash.utils.Timer;
	import flash.utils.getTimer;
	import flash.utils.getQualifiedClassName;
	import flash.system.Security;
	
	import caurina.transitions.*;
	[SWF(width="465", height="465", backgroundColor="0xffffff", frameRate="0")]
	public class NukumiZoom extends Sprite
	{	
		private var output:TextField;
		private var timer:Timer;
		private var frameRate:int = 24;
		private var t:int;
		
		private var nukumizu:Sprite;
		private var center:Point;
		private var numWorm:int = 4;
		private var canvas:Bitmap;
		public function NukumiZoom()
		{
			initOutput();
			println('Construct ', getQualifiedClassName(this));
			Security.loadPolicyFile('http://www.matzmtok.com/wonderfl/crossdomain.xml');
			addEventListener(Event.ADDED_TO_STAGE, addedToStage);
		}
		
		public function init():void {
			timer = new Timer(1000 / frameRate);
			timer.addEventListener(TimerEvent.TIMER, timerHandler);
			
			var req:URLRequest = new URLRequest("http://www.matzmtok.com/wonderfl/nukumizu.png");
			var l:Loader = new Loader();
			var c:LoaderContext = new LoaderContext(true);
			l.contentLoaderInfo.addEventListener(Event.OPEN, openHandler);
			l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
			l.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
			l.load(req,c);
			
			canvas = new Bitmap(new BitmapData(stage.stageWidth, stage.stageHeight));
			addChild(canvas);
		}
		
		private function startDemo():void {
			center = new Point(stage.stageWidth * 0.5, stage.stageHeight * 0.5);
			addChild(nukumizu);
			nukumizu.x = center.x;
			nukumizu.y = center.y;
			nukumizu.scaleX = 0.001;
			nukumizu.scaleY = 0.001;
			Tweener.addTween(nukumizu, { scaleX:2.5, scaleY:2.5, onComplete:resetTween, time:10, transition:"easeInBack" } );
			timer.start();
			
			hideOutput();
		}
		public function resetTween():void {
			//println("resetTween");
			canvas.bitmapData.fillRect(canvas.bitmapData.rect, 0x00000000);
			Tweener.removeTweens(nukumizu);
			nukumizu.x = center.x;
			nukumizu.y = center.y;
			nukumizu.scaleX = 0.001;
			nukumizu.scaleY = 0.001;
			Tweener.addTween(nukumizu, { scaleX:2.5, scaleY:2.5, onComplete:resetTween, time:10, transition:"easeInBack" } );
		}
		private function loop(dt:int):void {
			//println('loop', dt);
			//var rangeX:Number = nukumizu.scaleX * stage.stageWidth * 10;
			//var rangeY:Number = nukumizu.scaleY * stage.stageHeight * 10;
			var rangeX:Number = stage.stageWidth;
			var rangeY:Number = stage.stageHeight;
			if ( Math.random() < 0.4) {
				Tweener.addTween(nukumizu, { 
					x:(Math.random() * rangeX - rangeX * 0.5) + center.x,
					y:(Math.random() * rangeY - rangeY * 0.5) + center.y,
					time:10 * nukumizu.scaleX,
					transition:"linear"} );
			}
			if ( Math.random() < 0.1) {
				Tweener.addTween(nukumizu, { rotation:360 * Math.random() - 180, time:3, transition:"linear"} );
			}
			
			canvas.bitmapData.draw(nukumizu, nukumizu.transform.matrix);
		}
		
		private function timerHandler(e:TimerEvent):void 
		{
			var time:int = getTimer();
			loop(time - t);
			t = time;
		}
		private function addedToStage(e:Event):void 
		{
			removeEventListener(e.type, arguments.callee);
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			init();	
		}
		private function openHandler(e:Event):void {
			var li:LoaderInfo = e.target as LoaderInfo;
			println("Start Loading from " + li.url);
		}
		private function progressHandler(e:ProgressEvent):void {
			var li:LoaderInfo = e.target as LoaderInfo;
			var percent:Number;
			percent = 100 * li.bytesLoaded / li.bytesTotal;
			println("Loading " + Math.round(percent) + "%");
		}
		private function completeHandler(e:Event):void 
		{
			var li:LoaderInfo = e.target as LoaderInfo;
			print("Complete Loading ");
			print(li.url);
			println(getQualifiedClassName(li.content));
			var bitmap:Bitmap = li.content as Bitmap;
			nukumizu = new Sprite();
			nukumizu.addChild(bitmap);
			bitmap.x = -bitmap.width * 0.5;
			bitmap.y = -bitmap.height* 0.5;
			
			startDemo();
		}
		////////////////
		// 出力
		///////////////
		private function initOutput():void {
			var margin:Number = 10;
			
			addChild(output = new TextField());
			output.defaultTextFormat = new TextFormat("OCR A Std", 12);
			output.selectable = false;
			output.multiline = true;
			output.width = stage.stageWidth - margin * 2;	
			output.height = stage.stageHeight - margin * 2;	
		}
		public function print(... args):void {
			output.appendText(args.join(", "));
		}
		public function println(... args):void {
			output.appendText(args.join(", "));
			output.appendText("\n");
		}
		public function hideOutput():void {
			output.visible = false;
		}
		public function showOutput():void {
			output.visible = true;
		}
	}
}