Stop typewriter when loading new text

I’m having an issue when I’m trying to load new text into a typewriter function before it has finished writing the first text. Does anybody know how I can stop it?

TextField.prototype.typeWriter = function(str, ms) {
    var me = this;
    var i = 0;
    var itv = setInterval(function () {
        me.text = str.substring(0, i);
        i++;        
        if (i>str.length) {
            clearInterval(itv);
        }
        updateAfterEvent();
    }, ms);
};

(it’s found here http://proto.layer51.com/d.aspx?f=493)