forked from: forked from: forked from: forked from: flash on 2010-2-22
/**
* Copyright mhayashi ( http://wonderfl.net/user/mhayashi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/zqsC
*/
// forked from mhayashi's forked from: forked from: forked from: flash on 2010-2-22
// forked from mhayashi's forked from: forked from: flash on 2010-2-22
// forked from mhayashi's forked from: flash on 2010-2-22
// forked from mhayashi's flash on 2010-2-22
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class MyTextField extends Sprite {
public var fld:TextField;
public var msg:String = "楽しいActionScriptの世界へ";
public var timer:Timer;
public var charPos:uint;
public var counter:uint;
public var offset:uint;
public function MyTextField() {
// Text Field
fld = new TextField();
fld.x = 50;
fld.y = 50;
fld.autoSize = TextFieldAutoSize.LEFT;
fld.background = true;
fld.backgroundColor = 0xffff00;
// Text Format
var tf:TextFormat = new TextFormat();
tf.font = "_typewriter";
tf.size = 18;
tf.color = 0x0000FF;
fld.defaultTextFormat = tf;
addChild(fld);
timer = new Timer(100, fld.length);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();
}
public function timerHandler(event:TimerEvent):void {
var startCharCode:uint = msg.charCodeAt(charPos) - offset;
var char:String = String.fromCharCode(startCharCode + counter);
fld.text = msg.substring(0, charPos) + char + "_";
if(msg.charAt(charPos) == char){
if(charPos == msg.length - 1){
timer.stop();
fld.text = msg;
} else {
offset = Math.floor(30 * Math.random()) + 5;
charPos++;
counter = 0;
}
} else {
counter++;
}
}
}
}