MultilineText
tf.mouseEnabled = false;
tf.wordWrap = true;
package
{
import caurina.transitions.Tweener;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]
public class MultilineText extends Sprite
{
public function MultilineText()
{
var tf:TextField = new TextField();
tf.defaultTextFormat = new TextFormat("_typewriter", 12, 0xFF0000);
tf.width = stage.stageWidth;
tf.height = stage.stageHeight;
//tf.mouseEnabled = false;
tf.multiline = true;
//tf.wordWrap = true;
tf.text = getText();
tf.autoSize = "left";
addChild(tf);
showText(tf);
}
public function showText(target:TextField):void
{
var lines:Array = target.text.split("\r");
var n:uint = Math.min(lines.length, 40);
var str:String = "";
for (var i:uint = 0; i < n;i++ )
{
str += "\r";
Tweener.addTween(
{
index : 0,
rows : i,
target : target,
text : lines[i]
},
{
index : lines[i].length,
time : 1.0,
delay : i * 0.25 + 3,
transition : "easeoutsine",
onComplete : function():void
{
},
onUpdate : function():void
{
updateHandler(this);
}
});
}
target.text = str;
}
private function updateHandler(info:Object):void
{
var tf :TextField = info.target;
var str :String = info.text;
var begin :int = tf.getLineOffset(info.rows);
var end :int = begin + tf.getLineLength(info.rows) - 1;
tf.replaceText(begin, end, str.substr(0, info.index));
}
private function getText():String
{
return String(<![CDATA[package
{
import caurina.transitions.Tweener;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]
public class MultilineText extends Sprite
{
public function MultilineText()
{
var tf:TextField = new TextField();
tf.defaultTextFormat = new TextFormat("_typewriter", 12, 0xFF0000);
tf.width = stage.stageWidth;
tf.height = stage.stageHeight;
tf.mouseEnabled = false;
tf.multiline = true;
tf.text = getText();
addChild(tf);
showText(tf);
}
public function showText(target:TextField):void
{
var lines:Array = target.text.split("\r");
var n:uint = Math.min(lines.length, 20);
var str:String = "";
for (var i:uint = 0; i < n;i++ )
{
str += "\r";
Tweener.addTween(
{
index : 0,
rows : i,
target : target,
text : lines[i]
},
]]>);
}
}
}