Flash AS3 Typewriter Effect

1. Place a TextField on frame 1 and set the instance name to textbox
2. Enter the following code into frame 1

function typewriter(textBox:TextField, string:String, speed:int):void
{
//This gets the length of the string
var stringLength:Number = string.length;
//A counter
var counter:Number = 1;

function wait()
{
//If the end of the string is reached, stop timer
if (counter == stringLength)
{
clearInterval(myTimer);
}

//Display current text
textBox.text = string.substr(0,counter);
counter++;
}

//Start timer
var myTimer = setInterval(wait, speed);
}

//Call the function to make typewriter effect
typewriter(textbox, “dfsdfsdf”, 100);

3. Save and run and you should see the effect! The function takes 3 arguments: a textbox, a string to display, and the speed of the effect.

thanks http://egproductions.net/blog/

Leave a Reply