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: 【AS100本ノック】13回目:アルファベット

AS100本ノック
* 13回目のお題は「アルファベット」
* あなたなりの「アルファベット」を表現してください。
/**
 * Copyright mex_takagi ( http://wonderfl.net/user/mex_takagi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/xx4G
 */

// forked from mex's 【AS100本ノック】13回目:アルファベット
/**
 * AS100本ノック
 * 13回目のお題は「アルファベット」
 * あなたなりの「アルファベット」を表現してください。
 **/
package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.events.KeyboardEvent;
	/**
	 * @author Mao Takagi
	 */
	[SWF(width = "465", height = "465", backgroundColor = 0x000000, frameRate = "60")]
	public class Main extends Sprite 
	{
		private var _figureArray:Array;
		private var _figureMax:uint;
		private var _nowFigure:String;
		private var _nowGraphic:Figure;
		private var _count:uint;
		private var _countFormat:TextFormat;
		private var _countField:TextField;
		private var _title:Title;
		/**
		 * constructor
		 */
		public function Main():void 
		{
			_figureArray = ["a", "b", "c", "d", "e", "f", "g", 
							"h", "i", "j", "k", "l", "m", "n", 
							"o", "p", "q", "r", "s", "t", "u", 
							"v", "w", "x", "y", "z"];
			_figureMax = _figureArray.length;
			_count = 0;
			_title = new Title();
			_title.x = 10;
			_title.y = 10;
			_countFormat = new TextFormat();
			_countFormat.size = 12;
			_countFormat.align = "right";
			_countFormat.font = "ゴシック";
			_countFormat.bold = true;
			_countField = new TextField();
			_countField.defaultTextFormat = _countFormat;
			_countField.selectable = false;
			updateCount();
			_countField.x = 465 - _countField.width - 10;
			_countField.y = 10;
			generateFigure();
			addListener();
		}
		/**
		 * generateFigure
		 */
		private function generateFigure():void 
		{
			var rand:uint = Math.floor(Math.random() * _figureMax);
			_nowFigure = _figureArray[rand];
			//trace(rand, _nowFigure);
			var figure:Figure = new Figure(_nowFigure);
			figure.slideIn();
			if (_nowGraphic)
			{
				_nowGraphic.addEventListener(Event.COMPLETE, function():void
				{
					addListener();
					removeChild(_nowGraphic);
					_nowGraphic = figure;
				});
				_nowGraphic.slideOut();
			}
			else
			{
				_nowGraphic = figure;
			}
			addChild(figure);
			addChild(_countField);
			addChild(_title);
			
		}
		/**
		 * addListener
		 */
		private function addListener():void 
		{
			stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUpHandler);
		}
		/**
		 * addListener
		 */
		private function killListener():void 
		{
			stage.removeEventListener(KeyboardEvent.KEY_UP, onKeyUpHandler);
		}
		/**
		 * onKeyUpHandler
		 * @param event KeyboardEvent
		 */
		private function onKeyUpHandler(event:KeyboardEvent):void 
		{
			if (event.charCode == _nowFigure.charCodeAt(0))
			{
				killListener();
				//removeChildAt(0);
				generateFigure();
				_count++;
				updateCount();
			}
		}
		/**
		 * updateCount
		 */
		private function updateCount():void 
		{
			_countField.text = "SCORE:" + addZero(_count, 5);
		}
		/**
		 * addZero
		 * 
		 * @param num uint
		 * @param digit uint
		 * @return String
		 */
		public static function addZero(num:uint, digit:uint):String
		{
			var str:String = num.toString();
			var len:uint = str.length;
			var zeroNum:int = digit - len;
			if (zeroNum > 0)
			{
				var temp:String = "";
				for (var i:uint = 0; i < zeroNum;i++ )
				{
					temp += "0";
				}
				str = temp + str;
			}
			return str;
		}
	}
}

import flash.events.Event;
import flash.geom.Matrix;
import flash.text.TextField;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.text.TextFormat;
import flash.filters.ConvolutionFilter;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.events.TweenEvent;
import org.libspark.betweenas3.tweens.ITween;
import org.libspark.betweenas3.easing.Circ;
class Figure extends Sprite
{
	/**
	 * constructor
	 */
	public function Figure(figure:String)
	{
		x = 465;
		var format:TextFormat = new TextFormat();
		format.size = 1000;
		var field:TextField = new TextField();
		field.defaultTextFormat = format;
		field.autoSize = "left";
		field.text = figure;
		var bitmapDataBase:BitmapData = new BitmapData(field.width, field.height);
		bitmapDataBase.draw(field);
		
		var bitmapDataLeft:BitmapData = new BitmapData(465, 465 * 0.5);
		var bitmapLeft:Bitmap = new Bitmap(bitmapDataLeft);
		var matrixLeft:Matrix = new Matrix();
		matrixLeft.translate((465 - field.width) * 0.5, (465 - field.height) * 0.4);
		bitmapDataLeft.draw(field, matrixLeft);
		
		var bitmapDataRight:BitmapData = new BitmapData(465, 465 * 0.5);
		var bitmapRight:Bitmap = new Bitmap(bitmapDataRight);
		var matrixRight:Matrix = new Matrix();
		matrixRight.scale(1, -1);
		matrixRight.translate((465 - field.width) * 0.5, field.height * 0.7);
		bitmapDataRight.draw(bitmapDataBase, matrixRight);
		bitmapRight.y = 465 * 0.5;
		bitmapRight.filters = [new ConvolutionFilter(1, 1, [-1], 1, 255)];
		
		addChild(bitmapLeft);
		addChild(bitmapRight);
	}
	/**
	 * slideIn
	 */
	public function slideIn():void 
	{
		var t:ITween = BetweenAS3.tween(this, { x:0 }, null, 0.5, Circ.easeOut);
		t.addEventListener(TweenEvent.COMPLETE, function():void
		{
			t.removeEventListener(TweenEvent.COMPLETE, arguments.callee);
			dispatchEvent(new Event(Event.COMPLETE));
		});
		t.play();
	}
	/**
	 * slideOut
	 */
	public function slideOut():void 
	{
		var t:ITween = BetweenAS3.tween(this, {x:-465}, null, 0.5, Circ.easeOut);
		t.addEventListener(TweenEvent.COMPLETE, function():void
		{
			t.removeEventListener(TweenEvent.COMPLETE, arguments.callee);
			dispatchEvent(new Event(Event.COMPLETE));
		});
		t.play();
	}
}

import flash.text.TextField;
import flash.text.TextFormat;
class Title extends Sprite
{
	/**
	 * constructor
	 */
	public function Title()
	{
		var titleFormat:TextFormat = new TextFormat();
		titleFormat.size = 14;
		titleFormat.bold = true;
		var titleField:TextField = new TextField();
		titleField.defaultTextFormat = titleFormat;
		titleField.autoSize = "left";
		titleField.selectable = false;
		titleField.text = "Who am I??";
		
		var explainFormat:TextFormat = new TextFormat();
		explainFormat.size = 11;
		var explainField:TextField = new TextField();
		explainField.defaultTextFormat = explainFormat;
		explainField.autoSize = "left";
		explainField.selectable = false;
		explainField.text = "下の絵と同じキーをタイプしてください。お願いします。\nホントお願いします。\nでもSCOREが増えるだけです。すいません。\nホントすいません。";
		explainField.y = titleField.height;
		
		addChild(titleField);
		addChild(explainField);
	}
}