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: カタカタテキスト2

カタカタテキスト2
// forked from yanbaka's カタカタテキスト2
// カタカタテキスト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.display.Sprite;
    import flash.events.TimerEvent;
    import flash.text.TextField;
    import flash.utils.Timer;

    class Katakata extends Sprite
    {
        private var _tf: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;
        private var _timer:Timer = new Timer(33);
        //
        private var _over_str:String;
        private var _now_int:int;
        //

        public function Katakata(tf:TextField, last:String, char:String, delay:uint=10):void
        {
            _tf = tf;
            _last = last;
            _len = _last.length;
            _char = char;
            _delay = delay;
            //
            _over_str = "";
            //
            reset();

            _timer.addEventListener(TimerEvent.TIMER, animation);
        }

        private function reset():void
        {
            _tf.text = "";
            _over_str = "";
            _cnt = 0;
            _now_int = 0;
            _delayCnt = 0;

            _timer.start();
        }

        private function animation(e:TimerEvent):void
        {
            if(_len <= 0) return;

            var str:String = "";
            var i:uint= 0;
            if(_delayCnt > _delay)
            {
                if(_now_int == _char.length){
                    _over_str +=_last.charAt(_cnt);
                    _cnt++;

                    for (i = 0; i<_len-1; i++)
                    {
                        str += getRandomTxt();
                    }
                    _now_int = 0;
                    _len--;
                }else{
                    str = _char.charAt(_now_int);
                    _now_int++;
                    if(str == _last.charAt(_cnt)){
                        _now_int = _char.length;
                    }
                    for (i =0; i<_len-1; i++)
                    {
                        str += getRandomTxt();
                    }
                }

                if(_len <= 0)
                {
                    _timer.removeEventListener(TimerEvent.TIMER, animation);
                    _timer.stop();
                    str = "";
                }
                //
            }
            else
            {
                for (i=0; i<_len; i++)
                {
                    str += getRandomTxt();
                }
                _delayCnt++;
            }

            _tf.text = _over_str + 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;
        }
   }