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

forked from: Study AS3 [flash on 2009-9-27] BitmapData

200909272042
*
* Bitmapのお勉強。
*
* This file is for personal, free, non-commercial use.
* Please contact the author if you plan to use the file in other situations.
* Feel free to donate to the cause. 
* 
* 右上に自作アイコンを表示。クリックしたら同じ動作をする。
* 連続クリックでバグる。ある意味、面白い表現が出来るかも?!
*
*
* 20100429
* warningが表示されていたので修正。
* BitmapSnapShot.as(74): col: 24 Warning: parameter 'snapSize' has no type declaration.
* どんなパラメータなのかわかんねーよ。ちょっと指定してくれないか?というわーにんぐだったので
* 普通に、ナンバーで指定してやった。
*
Get Adobe Flash player
by xxxYukihiroxxx 29 Apr 2010

    Talk

    xxxYukihiroxxx at 28 Sep 2009 08:49
    I acquired a color, but want to make one one Box a random color.
    Embed
/**
 * Copyright xxxYukihiroxxx ( http://wonderfl.net/user/xxxYukihiroxxx )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/5dm7
 */

// forked from xxxYukihiroxxx's Study AS3 [flash on 2009-9-27] BitmapData
/*
 * 200909272042
 *
 * Bitmapのお勉強。
 *
 * This file is for personal, free, non-commercial use.
 * Please contact the author if you plan to use the file in other situations.
 * Feel free to donate to the cause. 
 * 
 * 右上に自作アイコンを表示。クリックしたら同じ動作をする。
 * 連続クリックでバグる。ある意味、面白い表現が出来るかも?!
 *
 *
 * 20100429
 * warningが表示されていたので修正。
 * BitmapSnapShot.as(74): col: 24 Warning: parameter 'snapSize' has no type declaration.
 * どんなパラメータなのかわかんねーよ。ちょっと指定してくれないか?というわーにんぐだったので
 * 普通に、ナンバーで指定してやった。
 *
 */


package 
{
    import flash.display.*;
    import flash.display.BitmapData;
    import flash.geom.Rectangle;
    import flash.geom.Matrix;
    import flash.events.*;

    import flash.utils.Timer;
    import flash.filters.*;
    import caurina.transitions.Tweener;

    import flash.net.URLRequest;

    [SWF(width = "465", height = "465", backgroundColor = "0xFFFFFF", frameRate = "120")]
	
    public class BitmapSnapShot extends MovieClip {
    		public var box:Sprite;
    		public var img:MovieClip;
		private var bitmapimg:BitmapData;
		private var pictures:Array = new Array();
		private var total:uint;
		private var count:uint = total;
		private var posx:uint;
		private var posy:uint;
		
		private var minuteTimer:Timer;
		private var cols:Number;
		private var rows:Number;
		private var bw:Number = 440;
		private var bh:Number = 400;

		public var snapSize:Number = 40;                
                
		public function BitmapSnapShot() {
			var loader:Loader = new Loader(); 
			addChild(loader);
			loader.load(new URLRequest("http://la-nouveau.dyndns.org/wonderfl/reroad_icon.gif"));

			// 画像の位置指定(px)
			loader.x = stage.stageWidth - loader.width - 30;
			loader.y = 10;
			
			addEventListener(MouseEvent.CLICK, playMotion);
			buttonMode = true;
			
			init(snapSize);
			
			function playMotion(event:MouseEvent):void {
				init(snapSize);
			}
		}
		
		public function init(snapSize:Number):void {
			box = new Sprite();
			//box.graphics.beginFill(0x000000);
			box.graphics.beginFill(Math.random() * 0xffffff);
			box.graphics.drawRect(0, 0, bw, bh);
			box.graphics.endFill();
			box.x = 12;
		    box.y = 12;
		    addChild(box);
				
			cols = box.width / snapSize;
			rows = box.height / snapSize;
			total = cols * rows;
			count = total;
				
			bitmapimg = new BitmapData(snapSize, snapSize, false, 0xFFFFFF);
				
			for (var i:uint = 0; i < total; i++) {
				img = new MovieClip();
				addChild(img);
				var myBitmap:Bitmap = new Bitmap(bitmapimg);
				img.addChild(myBitmap);
				pictures.push(img);
				pictures[i].x = box.x + (i % cols) * snapSize;
				pictures[i].y = box.y + Math.floor(i / rows) * snapSize;
				pictures[i].alpha = .9;
				bitmapimg.draw(box);
			}

			//hide the original box
			box.visible = false;
			startAnimation();
		}
		
		private function startAnimation():void {
			var calcTime:Number = total + 1;
			minuteTimer = new Timer(1, calcTime);

			// designates listeners for the interval and completion events
			minuteTimer.addEventListener(TimerEvent.TIMER, Animate);
			minuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);

			// starts the timer ticking
			minuteTimer.start();
		}

		private function ranDom(min:Number, max:Number):Number {
			//generates a random number between min and max
			var randomNum:Number = Math.floor(Math.random() * (max - min )) + min;
			return randomNum;
		}

		private function Animate(e:TimerEvent):void {			
			if (count >= 0) {
				var clip:MovieClip = pictures[count];
				var rot:Number = ranDom(-200, 250);
				//tween out
				Tweener.addTween(clip,{rotation:rot,time:5,transition:"linear"});
				Tweener.addTween(clip,{ y:stage.stageHeight+80,time:1.5,transition:"easeInOutBack", transitionParams:{overshoot:0.1}});
				Tweener.addTween(clip,{alpha:0,time:1,transition:"easeInQuart"});
				Tweener.addTween(clip,{_blur_blurX:10,_blur_blurY:10,time:.2,transition:"linear"});
				//
				if(count <= 0){
					AllDone();
				}
				count--;
			}
		}
		
		public function onTimerComplete(event:TimerEvent):void {
			minuteTimer.stop();
			removeEventListener(TimerEvent.TIMER, Animate);
			removeEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
		}
			
		private function AllDone():void {
			//reset everything and take fla to 2nd frame
			count = 0;
			total = 0;
			rows = 0;
			cols = 0;
			pictures = [];
			dispatchEvent(new Event("all done animation")); 
		}
	}
}