PDA

View Full Version : Animated textstring with AS



monAmour
February 26th, 2004, 04:54 AM
I'm trying to build a prototype for strings to be loaded into textfields.
I want to break up a string and put each and every char in it in to the textfield with a 1 second interval.

This is what I've come up with, I don't get any script errors but nothing seems to work anyway.
Any ideas how to accomplish this?


var myText:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wi";

TextField.prototype.animateString = function(strObj:String) {
var charCount:Number = strObj.length-1;
var c:Number = 0;
function animStr(strObj:String, strLength:Number) {
if (c < strLength) {
var input:String = strObj.charAt(c);
this.text = this.text + input;
c++;
animInt = setInterval(animStr, 1000);
}
else {
clearInterval(animInt);
}
}

animStr(strObj, charCount);
}

theText.animateString(myText);


Expl: This script is within the first frame of my movie. The textField named "theText" is also put there.

ScriptFlipper
February 26th, 2004, 11:03 AM
something like a typewriter?
is yes, this will do it:

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