Train of thought: 1. Create a dynamic text box first with AS, for output text;
2. Use a timer to accumulate output the next character at intervals.
As code layer:
_root.createTextField("output", 1, 0, 0, 500, 400);
var txt_f:TextFormat = new TextFormat();
txt_f.font = "宋体";
//设置字体
txt_f.color = 0x333333;
//设置文字颜色
txt_f.size = 22;
//设置文字大小
txt_f.bold = true;
//是否加粗
output.setNewTextFormat(txt_f);
//将设置好的属性赋给output
var timer = setInterval(display, 500);
//计时器,每0.5秒调用一次display函数
var txt:String = "输入要显示的字符串";
var i = 0;
//初始化
function display() {
output.text += txt.charAt(i);
//每次文字累加
if (i < txt.length-1){
i++;}
else {
clearInterval(timer);
}
}
//每隔一段时间输出下一个字符,全部输出后,清除掉计时器
Flash charge 1: The string is the same as the array subscript, starting at 0.
Flash charge 2: String common methods:
(1) String.charat: Returns a character in a string
s=new String("ABCDE");
trace(s.charAt(3));
//输出结果为"D"
(2) String.charcodeat: Returns the codewords of a character in a string
s=new String("ABCDE");
trace(s.charCodeAt(3));
//输出结果为68 .
(3) String.Concat: Connecting to other strings
a=new String("CAT,");
b=new String("PIG,")
c=new String("DOG")
trace(a.concat(b,c))
//输出结果为"CAT,PIG,DOG" .
(4) String.IndexOf: Looking for substrings, and returning pointers
s=new String("ABCDEF");
trace(s.indexOf("CDE"))
//输出结果为2 .