Simple typing

Source: Internet
Author: User
Tags setinterval

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 );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.