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 2009-3-6

Get Adobe Flash player
by naoto5959 06 Mar 2009
    Embed
package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	public class RandomCharGenerator extends Sprite
	{
		private var _txt:TextField;
		
		public function RandomCharGenerator()
		{
			_txt = new TextField();
			_txt.width = stage.stageWidth;
			_txt.height = stage.stageHeight;
			_txt.wordWrap = true;
			_txt.selectable = false;
			addChildAt(_txt, 0);
			stage.addEventListener(MouseEvent.CLICK, clickListener);
		}
		
		private function clickListener(event:Event):void
		{
			_txt.appendText(RandomChar.getChar());
		}
	}
}
class RandomChar
{
	/** ひらがなの開始コード */
	private static const HIRAGANA_START:uint = 0x3041;
	/** ひらがなの終了コード */
	private static const HIRAGANA_END:uint = 0x3093;
	
	/** 全角カタカナの開始コード */
	private static const KATAKANA_START:uint = 0x30a1;
	
	/** 全角カタカナの終了コード */
	private static const KATAKANA_END:uint = 0x30f6;
	
	/** CJK統合漢字の開始コード */
	private static const CJK_START:uint = 0x4e00;
	
	/** CJK統合漢字の開始コード */
	private static const CJK_END:uint = 0x9fff;
	
	public static function getChar():String
	{
		var chars:Array = [getHiragana(), getKatakana(), getCJK()];
		return chars[Math.floor(Math.random() * chars.length)];
	}
	
	private static function getHiragana():String
	{
		return String.fromCharCode(createRandom(HIRAGANA_START, HIRAGANA_END));
	}
	
	private static function getKatakana():String
	{
		return String.fromCharCode(createRandom(KATAKANA_START, KATAKANA_END));
	}
	
	private static function getCJK():String
	{
		return String.fromCharCode(createRandom(CJK_START, CJK_END));
	}
	
	private static function createRandom(minCode:uint, maxCode:uint):uint
	{
		return Math.floor(Math.random() * (maxCode - minCode + 1)) + minCode;
	}
}