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

Bitmap Effect

ちょっとしたBitmapのエフェクト
/**
 * Copyright demouth ( http://wonderfl.net/user/demouth )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/hBmi
 */

/* ちょっとしたBitmapのエフェクト
 */
package 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;
	
	[SWF(width=465,height=465,frameRate=60)]
	public class FlashTest extends Sprite
	{
		private var originalBD:BitmapData;
		private var mat:Matrix;
		private var diff:int = 0;
		private var flg:Boolean;//いったりきたりフラグ
		
		public function FlashTest() 
		{
			this.init();
		}
		
		private function init():void
		{
			var loader:Loader = new Loader();
			loader.load(new URLRequest("http://assets.wonderfl.net/images/related_images/9/91/9162/91627668adccfd301dc3ed71291750aac8958864"),new LoaderContext(true));
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteHandler);
		}
		
		private function loadCompleteHandler(e:Event):void 
		{
			this.originalBD = ((e.currentTarget as LoaderInfo).loader.content as Bitmap).bitmapData;
			
			var scale:Number =
				(this.originalBD.width > this.originalBD.height)?
				this.stage.stageHeight / this.originalBD.height:
				this.stage.stageWidth  / this.originalBD.width;
			
			this.mat = new Matrix();
			this.mat.scale(scale, scale);
			this.stage.addEventListener(Event.ENTER_FRAME , enterFrameHandler);
		}
		
		private function enterFrameHandler(e:Event):void 
		{
			var move:int=3;
			//いったりきたりさせてる
			if (((this.originalBD.width-this.diff) <= move+1 || (this.originalBD.height-this.diff) <= move+1 )||this.diff <= 0)
			{
				this.flg = !this.flg;
			}
			if (this.flg) this.diff+=move
			else this.diff-=move;
			
			var bitmapData:BitmapData = new BitmapData(this.originalBD.width-this.diff,this.originalBD.height-this.diff);
			bitmapData.copyPixels(this.originalBD, this.originalBD.rect, new Point());
			
			this.graphics.clear();
			this.graphics.beginBitmapFill(bitmapData, this.mat, false);
			this.graphics.drawRect(0, 0, this.stage.stageWidth, this.stage.stageHeight);
			this.graphics.endFill();
		}
	}

}