# setInterval / for loop

**URL:** <https://forum.kirupa.com/t/setinterval-for-loop/18826>\
**Category:** flash\
**Created:** [April 21, 2003, 6:09pm UTC](https://forum.kirupa.com/t/setinterval-for-loop/18826 "2003-04-21T18:09:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shuga](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@shuga](https://forum.kirupa.com/u/shuga)\
**Post date:** [April 21, 2003, 6:09pm UTC](https://forum.kirupa.com/t/setinterval-for-loop/18826/1 "2003-04-21T18:09:32Z")

</div>

```php

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 21, 2003, 6:33pm UTC](https://forum.kirupa.com/t/setinterval-for-loop/18826/2 "2003-04-21T18:33:02Z")

</div>

just shooting in the dark here… 😛

```auto
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);

```

=)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 21, 2003, 8:11pm UTC](https://forum.kirupa.com/t/setinterval-for-loop/18826/3 "2003-04-21T20:11:55Z")

</div>

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

🙂 other than that it works great

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 21, 2003, 8:15pm UTC](https://forum.kirupa.com/t/setinterval-for-loop/18826/4 "2003-04-21T20:15:37Z")

</div>

so true… totally forgot about that. 😛

try this one:

```auto
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);

```
