setInterval / for loop


for (i=0; i<link.length; i++) {
	_root.divisions.createEmptyMovieClip("mc"+i, i);
	with (_root.divisions["mc"+i]) {
		createTextField("label", 1003, 268, -155+(20*i), 90, 16);
		with (label) {
			background = true;
			border = true;
			borderColor = 0x003399;
			backgroundColor = 0xF2F4FA;
			type = "dynamic";
			text = _root.divisions.link*;
			selectable = false;
			setTextFormat(myFormat);
		}
	}

that’s the code i have to create a menu dynamically using an array called link to get feed the text into the buttons.

how would i use setInterval in that for loop so that the buttons don’t appear all at once.

just shooting in the dark here… :stuck_out_tongue:

createMenu = function () {
	i<link.length ? i++ : clearInterval(myInterval);
	_root.divisions.createEmptyMovieClip("mc"+i, i);
	with (_root.divisions["mc"+i]) {
		createTextField("label", 1003, 268, -155+(20*i), 90, 16);
		with (label) {
			background = true;
			border = true;
			borderColor = 0x003399;
			backgroundColor = 0xF2F4FA;
			type = "dynamic";
			text = _root.divisions.link*;
			selectable = false;
			setTextFormat(myFormat);
		}
	}
};
// this interval would create the menu at 24 fps
myInterval = setInterval(createMenu, 1000/24);

=)

lol … when i put it in … the labels were created with value 1 as the first item

so the array containing the label names called link starts at value 0 obviously … and the boxes were created in the proper quantity but the first box had value 1 in it instead of value 0 and the last box was empty

:slight_smile: other than that it works great

so true… totally forgot about that. :stuck_out_tongue:

try this one:

var i = 0;
createMenu = function () {
_root.divisions.createEmptyMovieClip("mc"+i, i);
with (_root.divisions["mc"+i]) {
createTextField("label", 1003, 268, -155+(20*i), 90, 16);
with (label) {
background = true;
border = true;
borderColor = 0x003399;
backgroundColor = 0xF2F4FA;
type = "dynamic";
text = _root.divisions.link*;
selectable = false;
setTextFormat(myFormat);
}
}
i<link.length ? i++ : clearInterval(myInterval);
};
myInterval = setInterval(createMenu, 1000/24);