I’m creating a preloader that loops through an array of adjectives and then stops on one of the words in the array. My code actually works, but, I also receive a “256 levels of recursion” error message in the Output dialog. That’s not so great. I wonder if anyone knows of a cleaner way to code this. (Note: I’m working in MX 2004.)
loadArray = new Array("vivid", "effervescent", "luminous", "powerful", "concise", "spontaneous", "mischievous", "radiant");
formatText = new TextFormat();
formatText.font = "Interstate-Regular";
formatText.size = 18;
formatText.color = "0xFFFFFF";
formatText.embedFonts = true;
formatText.selectable = false;
preload_txt.text = loadArray[0];
// Load first item in array
var elapsedSeconds:Number;
var n:Number = 0;
var nCount:Number = 0;
function loopText() {
if (n<loadArray.length-1) {
n++;
} else {
n = 0;
}
preload_txt.text = loadArray[n];
preload_txt.autoSize = "right";
preload_txt.setTextFormat(formatText);
nCount++; // Let nCount reach 8 plus a random number between 1 and 7
if (nCount>8+(Math.floor(Math.random()* 7 + 1))) {
delete this.loopText();
}
}
function initLoop() {
countInt = setInterval(this, "loopText", 100);
}
initLoop();
stop();