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

flash on 2010-4-13

Get Adobe Flash player
by kihon 13 Apr 2010
    Embed
/**
 * Copyright kihon ( http://wonderfl.net/user/kihon )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/wj0I
 */

package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;
 
	public class Main extends Sprite
	{
		private var charaChip:BitmapData;
		private const C_WIDTH:int = 32;
		private const C_HEIGHT:int = 48;
 
		private var frame:int = 0;
		private var cx:int = 0;
		private var cy:int = 0;
		private var prevcy:int = 0;
		private var chara:BitmapData;
 
		private var left:Boolean = false;
		private var right:Boolean = false;
		private var top:Boolean = false;
		private var bottom:Boolean = false;
		private var player:Bitmap;
 
		private const SPEED:int = 10;
 
		public function Main()
		{
			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
			loader.load(new URLRequest("http://assets.wonderfl.net/images/related_images/3/33/3384/3384200b2dc435c82a6c311375c2e26b81bc80e2"), new LoaderContext(true));
		}
 
		private function initHandler(event:Event):void
		{
			var loader:Loader = event.currentTarget.loader;
			charaChip = new BitmapData(loader.width, loader.height, true, 0x0);
			charaChip.draw(loader);
			charaChip.threshold(charaChip, charaChip.rect, new Point(), "==", 0x78c380, 0x0, 0xFFFFFF);
 
			chara = new BitmapData(C_WIDTH, C_HEIGHT, true, 0x0);
			player = new Bitmap(chara);
			player.scaleX = player.scaleY = 2;
			addChild(player);
 
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
			stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
			stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
		}
 
		private function onEnterFrame(event:Event):void
		{
			if (left) player.x -= SPEED, cy = 1;
			else if (right) player.x += SPEED, cy = 2;
			else if (top) player.y -= SPEED, cy = 3;
			else if (bottom) player.y += SPEED, cy = 0;
 
			if (prevcy != cy || frame++ % 10 == 0)
			{
				chara.copyPixels(charaChip, new Rectangle(C_WIDTH * (cx + 6), C_HEIGHT * cy, C_WIDTH, C_HEIGHT), new Point());
				cx = (cx + 1) % 3;
				prevcy = cy;
			}
		}
 
		private function onKeyDown(event:KeyboardEvent):void
		{
			if (event.keyCode == 37) left = true;
			if (event.keyCode == 39) right = true;
			if (event.keyCode == 38) top = true;
			if (event.keyCode == 40) bottom = true;
		}
 
		private function onKeyUp(event:KeyboardEvent):void
		{
			if (event.keyCode == 37) left = false;
			if (event.keyCode == 39) right = false;
			if (event.keyCode == 38) top = false;
			if (event.keyCode == 40) bottom = false;
		}
	}
}