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

Party

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

package 
{
	import flash.display.Sprite;
	import flash.events.*;
	
	[SWF(width="465", height="465", frameRate="30", backgroundColor="0x000000")]
	public class Main extends Sprite 
	{
		private const majoImgList:Array = [
			"http://flash-scope.com/wonderfl/WonderflQuest/majo/majoF1.png",	//前向き1
			"http://flash-scope.com/wonderfl/WonderflQuest/majo/majoF2.png",	//前向き2
			"http://flash-scope.com/wonderfl/WonderflQuest/majo/majoB1.png",	//後ろ向き1
			"http://flash-scope.com/wonderfl/WonderflQuest/majo/majoB2.png",	//後ろ向き2
			"http://flash-scope.com/wonderfl/WonderflQuest/majo/majoL1.png",	//左向き1
			"http://flash-scope.com/wonderfl/WonderflQuest/majo/majoL2.png",	//左向き2
			"http://flash-scope.com/wonderfl/WonderflQuest/majo/majoR1.png",	//右向き1
			"http://flash-scope.com/wonderfl/WonderflQuest/majo/majoR2.png"		//右向き2
		];
		
		private const souryoImgList:Array = [
			"http://flash-scope.com/wonderfl/WonderflQuest/souryo/souryoF1.png",	//前向き1
			"http://flash-scope.com/wonderfl/WonderflQuest/souryo/souryoF2.png",	//前向き2
			"http://flash-scope.com/wonderfl/WonderflQuest/souryo/souryoB1.png",	//後ろ向き1
			"http://flash-scope.com/wonderfl/WonderflQuest/souryo/souryoB2.png",	//後ろ向き2
			"http://flash-scope.com/wonderfl/WonderflQuest/souryo/souryoL1.png",	//左向き1
			"http://flash-scope.com/wonderfl/WonderflQuest/souryo/souryoL2.png",	//左向き2
			"http://flash-scope.com/wonderfl/WonderflQuest/souryo/souryoR1.png",	//右向き1
			"http://flash-scope.com/wonderfl/WonderflQuest/souryo/souryoR2.png"		//右向き2
		];                                                        
		private var majo:Party;
		private var souryo:Party;
		
		private var keyFlags:Array = [false, false, false, false]; //下上左右のキーが押されているか
		private var frameCount:Number = 0;	//onEnterFrameで使用
		
		public function Main():void 
		{
			majo = new Party(majoImgList);
			souryo = new Party(souryoImgList);
			majo.scaleX = majo.scaleY = 3;
			souryo.scaleX = souryo.scaleY = 3;
			majo.x = 160.5;
			souryo.x = 256.5;
			majo.y = souryo.y = 208.5;
			addChild(majo);
			addChild(souryo);
			
			addEventListener(Event.ENTER_FRAME, onEnterFrame);//イベントリスナーの登録
			stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);	//イベントリスナーの登録
			stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);		//イベントリスナーの登録
		}
		
		/**-----------------------------------------------------
		 * 毎フレームの処理。
		 * ----------------------------------------------------- */
		private function onEnterFrame(event:Event):void {
			
			//15フレーム毎に処理する
			if (frameCount++ > 10) {
				frameCount = 0;
				majo.walk();
				souryo.walk();
			}
			
			switch(true) {
				case keyFlags[0]:	//下
					majo.changeDirection(0);
					souryo.changeDirection(0);
					break;
				case keyFlags[1]:	//上
					majo.changeDirection(1);
					souryo.changeDirection(1);
					break;
				case keyFlags[2]:	//左
					majo.changeDirection(2);
					souryo.changeDirection(2);
					break;
				case keyFlags[3]:	//右
					majo.changeDirection(3);
					souryo.changeDirection(3);
					break;
			}
			
		}
		
		/**-----------------------------------------------------
		 * キーボードのキーが押された時の処理。
		 * ----------------------------------------------------- */
		private function onKeyDown(event:KeyboardEvent):void {
			switch(event.keyCode) {
				case 40: case 83:	//↓ s
					keyFlags[0] = true;
			}
			switch(event.keyCode) {
				case 38: case 87:	//↑ w
					keyFlags[1] = true;
			}
			switch(event.keyCode) {
				case 37: case 65:	//← a
					keyFlags[2] = true;
			}
			switch(event.keyCode) {
				case 39: case 68:	//→ d
					keyFlags[3] = true;
			}
		}
		
		/**-----------------------------------------------------
		 * キーボードのキーが離された時の処理。
		 * ----------------------------------------------------- */
		private function onKeyUp(event:KeyboardEvent):void {
			switch(event.keyCode) {
				case 40: case 83:	//↓ s
					keyFlags[0] = false;
			}
			switch(event.keyCode) {
				case 38: case 87:	//↑ w
					keyFlags[1] = false;
			}
			switch(event.keyCode) {
				case 37: case 65:	//← a
					keyFlags[2] = false;
			}
			switch(event.keyCode) {
				case 39: case 68:	//→ d
					keyFlags[3] = false;
			}
		}
	}
	
}

import flash.display.Sprite;
import flash.display.Loader;
import flash.net.URLRequest;
/**-----------------------------------------------------
 * 勇者クラスです。勇者を作ったり、足踏させたり、向きを変えたりします。
 * ----------------------------------------------------- */
class Party extends Sprite {
	public var direction:int = 0;		//向き (0:前 1:後 2:左 3:右)
	private var walkFlag:Boolean = true;//足踏み用
	private var yuushaImages:Array = [];//画像集
	private var ImageURL:Array;
	
	/**-----------------------------------------------------
	 * コンストラクタ。
	 * ----------------------------------------------------- */
	public function Party(imgList:Array):void {
		ImageURL = imgList;
		for (var i:uint = 0; i < 8; i++) {
			var loader:Loader = new Loader();
			loader.load(new URLRequest(ImageURL[i]));
			yuushaImages.push(loader);
			if(i) yuushaImages[i].visible = false;
			addChild(yuushaImages[i]);
		}
	}
	
	/**-----------------------------------------------------
	 * 足踏みさせます。
	 * ----------------------------------------------------- */
	public function walk():void {
		walkFlag = !walkFlag;
		for (var i:uint = 0; i < 8; i++) {
			if (i == 2*direction+int(walkFlag)) yuushaImages[i].visible = true;
			else yuushaImages[i].visible = false;
		}
	}
	
	/**-----------------------------------------------------
	 * 向きを変更します。
	 * numは向きを表します。(0~3)
	 * ----------------------------------------------------- */
	public function changeDirection(num:int):void {
		direction = num;
		for (var i:uint = 0; i < 8; i++) {
			if (i == 2*direction+int(walkFlag)) yuushaImages[i].visible = true;
			else yuushaImages[i].visible = false;
		}
	}
}