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

カタカタテキスト2

カタカタテキスト2
Get Adobe Flash player
by yanbaka 30 Apr 2009
// カタカタテキスト2
package
{
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.utils.Timer;
	
	[SWF(width = "465", height = "465", backgroundColor = "0xFFFFFF", frameRate = "30")]
	public class KatakataText2 extends Sprite
	{
		private var _mainTf:TextField;
		private var _inputTf:TextField;
		
		private var timer:Timer;
		private var interval:uint = 5000;
		
		private var katakata:Katakata;
		
		
		public function KatakataText2():void
		{
			var label:TextField = addChild(new TextField()) as TextField;
			label.x = 50;
			label.y = 20;
			label.autoSize = TextFieldAutoSize.LEFT;
			label.text = "カタカタテキスト2。出方をちょっと変更しました。";
			
			_inputTf = addChild(new TextField()) as TextField;
			_inputTf.x = 50;
			_inputTf.y = 70;
			_inputTf.type = TextFieldType.INPUT;
			_inputTf.maxChars = 30;
			_inputTf.border = true;
			_inputTf.width = 200;
			_inputTf.height = 20;
			_inputTf.text = "hogehogehogehogehogehoge";
			
			_mainTf = addChild(new TextField()) as TextField;
			_mainTf.x = 50;
			_mainTf.y = 95;
			_mainTf.autoSize = TextFieldAutoSize.LEFT;
			setFormat(_mainTf, 20);
			
			timer = new Timer(interval);
			timer.addEventListener(TimerEvent.TIMER, timerHandler);
			timer.start();
			
			// 最初
			katakata = new Katakata(_mainTf, _inputTf.text, "!#/_-+abcdefghijklmnopqrstuvwxyz0123456789");
		}
		
		private function timerHandler(e:TimerEvent):void
		{
			katakata = new Katakata(_mainTf, _inputTf.text, "!#/_-+abcdefghijklmnopqrstuvwxyz0123456789");
		}
		
		private function setFormat(tf:TextField, _size:Number):void
		{
			var format:TextFormat = new TextFormat();
			format.size = _size;
			tf.defaultTextFormat = format;
		}
		
	}
}
	import flash.events.Event;
	import flash.text.TextField;
	import flash.display.Sprite;
	

	class Katakata extends Sprite
	{
		private var _tf:TextField;
		private var _addTf:TextField = new TextField;
		private var _last:String;
		private var _len:uint;
		private var _char:String;
		private var _cnt:uint;
		private var _delay:uint;
		private var _delayCnt:uint;
		
		
		public function Katakata(tf:TextField, last:String, char:String, delay:uint=10):void
		{
			_tf = tf;
			_last = last;
			_len = _last.length;
			_char = char;
			_delay = delay;
			
			reset();
			
			addEventListener(Event.ENTER_FRAME, animation);
		}
		
		private function reset():void
		{
			_tf.text = "";
			_addTf.text = "";
			_cnt = 0;
			_delayCnt = 0;
		}
		
		private function animation(e:Event):void
		{
                        if(_len <= 0) return;
                        
			var str:String = "";
			if(_delayCnt > _delay)
			{
				_addTf.appendText(_last.charAt(_cnt));
				_cnt++;
				
				for (var i:uint=0; i<_len-1; i++)
				{
					str += getRandomTxt();
				}
				_len--;
				if(_len <= 0)
				{
					removeEventListener(Event.ENTER_FRAME, animation);
					str = "";
				}
			}
			else
			{
				for (i=0; i<_len; i++)
				{
					str += getRandomTxt();
				}
				_delayCnt++;
			}
			_tf.text = _addTf.text + str;
		}
		
		private function getRandomTxt():String
		{
			return _char.charAt(getRandomInt(_char.length-1, 0));
		}
		
		private function getRandomInt(max:uint, min:uint):uint
		{
			return Math.floor(Math.random()*(max-min+1))+min;
		}
	}