Here is a fairly simple way of making “typewriter’ style text with just a couple lines of Actionscript. It’s easy, fast and fun for the whole family!
Ok here we go.
1) Create a new flash file. (simple right?!?)
2) Make two layers. Name the top one “actions” and lock it. Then name the bottom one “text field”

3)Now open the actions panel and we are going to make two global variables for our typewriter function to reference while it is spelling out our string.
var count:int;
var string:String;
4) Next we create the initializing function that will set our global variables and then add our Event.ENTER_FRAME Listener. If you are not familiar with the ENTER_FRAME event, essentially what it does is every time your flash file advances one frame, whatever functions you have set up to listen for this event will be fired off.
function initTypewriter(_string:String):void
{
count = 0;
string = _string;
addEventListener(Event.ENTER_FRAME, writeType);
}
5) Now comes the workhorse function that will parse through your string and write the text to (our soon to be placed on the stage) text field.
function writeType(e:Event):void
{
if (count < string.length+1)
{
textField_txt.text = string.substr(0, count);
count++;
}
else
{
removeEventListener(Event.ENTER_FRAME, writeType);
}
}
6) Back on the stage we are going to add a textfield, set it to dynamic and name it “textField_txt”. (you can use whatever font you’d like, just make sure if it is not a web safe font like Times New Roman or Arial you will have to embed whichever characters you plan on using).
7)Last but not least, we call the function in our code!
initTypeWriter("your text string here!");
There you go!
-J


Stumble it!

J.
Thanks so much for this cool little tutorial, it works great. Here’s my problem, I’d like this to work with pulling the text from an external text file. Can this be done? I hate to ask, but I’m more of a designer than a programmer, I know enough AS3 to be dangerous.
Thanks for any guidance you can lend.
Best,
Dave
Hi Dave,
Thanks so much for the comment. Adding external text would be pretty easy. Put the following code in place of the initTypWriter(“string”) function now.:
var textLoader:URLLoader = new URLLoader(new URLRequest(“thePathtoYourTextFile.txt”));
textLoader.addEventListener(Event.COMPLETE, function (e:Event):void{
initTypeWriter(e.target.data);
}
Make sure your .txt file is in the same directory as the .swf and change the name of the URLRequest to match the name of your .txt file.
-J