Step 1: import a typing sound to the first frame in the home scene, and set the sound to "event" and "loop" in the attribute panel ". (If the sound in the library is loaded, the loading time is not good)
Step 2: write the following code on the frame ----
// Declare the variable
Var my_sound: Sound = new Sound (_ root );
Var id: Number = setInterval (dazi, 100 );
Var I: Number = 0;
Var my_fmt: TextFormat = new TextFormat ();
Var my_str: String = "invalid jdlksjfl, qerjlqj, moen k lov e. ";
// Create dynamic text
This. createTextField ("my_txt", 1, 30, 10,120, 20 );
// Control the automatic size adjustment and left alignment of text fields
My_txt.autoSize = true;
// Set text line spacing
My_fmt.leading = 6;
// Set the text color
My_fmt.color = 0 xFFFFFF;
// Apply the new text format to dynamic text
My_txt.setNewTextFormat (my_fmt );
// User-defined functions
Function dazi (){
// If the variable I is not greater than the number of my_str characters
If (I <= length (my_str )){
// Display the characters of my_str in dynamic text (starting from the first character with the length of I)
My_txt.text = my_str.substr (0, I );
// Variable increments by 1
I ++;
}
// If the variable I is greater than the number of my_str characters
If (I> length (my_str )){
// Sound stops
My_sound.stop ();
// Stop setInterval () call
ClearInterval (id );
}
}