Flash geekery – typewriter animation effect

Usually only talk music and video in this blog, but as I don’t have a professional blog atm (maybe I should) here’s a cool Flash thing I did.

I wanted to do a typewriter effect, you know where each letter types on – top Google hit is this very old-school solution with some mistakes. So I recoded it with a function and clearInterval, it types then continues when finished, this way you can change the speed of the text by changing the interval. You could do it with onEnterFrame but I like setInterval, far more flexible as you can change the interval, although you could do a counter so your mileage may vary 🙂

You need a textfield called ‘question’ on the timeline, and that’s all.

var txt:String = "This text is being typed out by code. Isn't it cool?";
var max:Number = length(txt);
var loop:Number = 1;
var interval:Number;

function typeLoop() {
question.text = substring(txt, 1, loop);
if (loop>max) {
} else {
interval = setInterval(typeLoop, 50);

Yes it could be whizzier – this is Actionscript 2, not 3, you could do a class, but to my mind that’s cracking a nut with a sledgehammer! Simple but I have more complex stuff I do, maybe I should share it…

Yup this is my day job, although more animation than code….

Relatio Clash

Be First to Comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.