forked from: forked from: あのお方のテキストアニメーションを真似してみる
// forked from taka_milk's forked from: あのお方のテキストアニメーションを真似してみる
// forked from yanbaka's あのお方のテキストアニメーションを真似してみる
package
{
import flash.display.Sprite;
import flash.events.Event;
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 YanbakaText extends Sprite
{
private var _mainTf:TextField;
private var _inputTf:TextField;
private var _tf:TextField;
private var _addTf:TextField = new TextField;
private var _last:String;
private var _len:uint;
private var _char:String;
private var _spd:uint;
private var _spdCnt:uint;
private var _cnt:uint;
private var timer:Timer;
private var interval:uint = 100000;
public function YanbakaText():void
{
var label:TextField = addChild(new TextField()) as TextField;
label.x = 50;
label.y = 20;
label.autoSize = TextFieldAutoSize.LEFT;
_inputTf = addChild(new TextField()) as TextField;
_inputTf.x = 50;
_inputTf.y = 70;
_inputTf.type = TextFieldType.INPUT;
_inputTf.maxChars = 20;
_inputTf.border = true;
_inputTf.width = 200;
_inputTf.height = 20;
_inputTf.text = "actionscript";
_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();
// 最初
yText(_mainTf, _inputTf.text, "!#/_-+abcdefghijklmnopqrstuvwxyz0123456789");
}
private function timerHandler(e:TimerEvent):void
{
_mainTf.text = "";
_addTf.text = "";
_cnt = 0;
_spdCnt = 0;
yText(_mainTf, _inputTf.text, "!#/_-+abcdefghijklmnopqrstuvwxyz0123456789");
}
private function yText(tf:TextField, last:String, char:String, spd:uint=5):void
{
_tf = tf;
_last = last;
_len = _last.length;
_char = char;
_spd = spd;
addEventListener(Event.ENTER_FRAME, animation);
}
private function animation(e:Event):void
{
if(_len <= 0) return;
if(_spdCnt >= _spd)
{
_spdCnt = 0;
_addTf.appendText(_last.charAt(_cnt));
_cnt++;
if(_cnt >= _len)
{
removeEventListener(Event.ENTER_FRAME, animation);
_char = "";
}
}
else
{
_spdCnt++;
}
_tf.text = _addTf.text + _char.charAt(getRandomInt(_char.length-1, 0));
}
private function setFormat(tf:TextField, _size:Number):void
{
var format:TextFormat = new TextFormat();
format.size = _size;
tf.defaultTextFormat = format;
}
private function getRandomInt(max:uint, min:uint):uint
{
var random:uint = Math.floor(Math.random()*(max-min+1))+min;
return random;
}
}
}