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

by uwi forked from forked from: Study AS3 [flash on 2009-9-27] BitmapData (diff: 50)
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.
* どんなパラメータなのかわかんねーよ。ちょっと指定してくれないか?というわーにんぐだったので
* 普通に、ナンバーで指定してやった。
*
♥0 | Line 108 | Modified 2010-04-30 21:52:11 | MIT License
play

ActionScript3 source code

/**
 * Copyright uwi ( http://wonderfl.net/user/uwi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/A0ec
 */

// forked from xxxYukihiroxxx's forked from: Study AS3 [flash on 2009-9-27] BitmapData
// 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 picturess: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;
				
			cols = box.width / snapSize;
			rows = box.height / snapSize;
			total = cols * rows;
			count = total;
			
			bitmapimg = new BitmapData(snapSize, snapSize, false, 0xFFFFFF);
			bitmapimg.draw(box);
				
			var pictures : Array = [];
			// this / img / myBitmap / bitmapimg
			for (var i:int = total - 1; i >= 0; i--) {
				img = new MovieClip();
				addChild(img);
				var myBitmap:Bitmap = new Bitmap(bitmapimg);
				img.addChild(myBitmap);
				img.x = box.x + (i % cols) * snapSize;
				img.y = box.y + Math.floor(i / rows) * snapSize;
				img.alpha = .5;
				
				pictures.push(img);
			}
			picturess.push(pictures);

			//hide the original box
			box.visible = false;
			startAnimation();
		}
		
		private function startAnimation():void {
			var calcTime:Number = total + 1;
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
//			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 var _t : Number = 0;
		
//		private function Animate(e:TimerEvent):void {			
		private function onEnterFrame(e:Event):void {	
			if(_t % 1 == 0){
				for(var i : uint = 0;i < picturess.length;i++){
					var pictures : Array = picturess[i];
					if (pictures.length > 0) {
						var clip:MovieClip = pictures.shift();
						var rot:Number = ranDom(-200, 250);
						//tween out
						Tweener.addTween(clip,{rotation:rot,time:5,transition:"linear", onComplete:function():void{removeChild(clip);}});
						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"});
					}else{
						// remove
						if(i == picturess.length - 1){
							picturess.pop();
						}else{
							picturess[i] = picturess.pop();
						}
					}
				}
			}
			_t++;
		}
		
		/*
		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")); 
		}
	}
}