Computer Type effect

Im trying to create a dynamic text typing effect that will type the text from a variable like a computer with a cursor in front of the text.

There’s a dynamic textbox with variable field on stage
cursor is a blinking rectangular movie clip designed to precede the text.

Here’s the code I got so far:


field = "";
startx = 13;
i = 0;
msg1 = "Connecting... ";
_root.onEnterFrame = function() {
    field += msg1.charAt(i);
        startx = startx+30;
    i++;
    cursor._x = startx;
};

With this code, the cursor follows the text but keeps on going after msg1 has been typed out.

  1. How can I get it to stop typing when its finished the message?

2.Also, is there a way to slow the text typing down? Make it so there is a slight delay between each character typed?
[SIZE=1]
p.s. how do I wrap actionscript tags around text?[/SIZE]