# Delay (setInterval) with attachmovie

**URL:** <https://forum.kirupa.com/t/delay-setinterval-with-attachmovie/184582>\
**Category:** Uncategorized\
**Created:** [April 6, 2006, 1:22am UTC](https://forum.kirupa.com/t/delay-setinterval-with-attachmovie/184582 "2006-04-06T01:22:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![inVZbl](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/invzbl/32/309_2.png) [@inVZbl](https://forum.kirupa.com/u/inVZbl)\
**Post date:** [April 6, 2006, 1:22am UTC](https://forum.kirupa.com/t/delay-setinterval-with-attachmovie/184582/1 "2006-04-06T01:22:40Z")

</div>

i created a menu using the xml tute example and made some modifications to what i needed but now need to add a delay when using attachmovie to add clips to the stage. I have tried to use setInterval, but couldnt get it to work so far.

This is part of the code im using to attach the movies to the stage…

```auto
// for all items or XML nodes (items and menus)
// within this node_xml passed for this menu
for (var i=0; i<node_xml.childNodes.length; i++) {

// movieclip for each menu item
if (node_xml.childNodes*.nodeName == "menu"){
curr_item = curr_menu.attachMovie("menuitem","item"+i+"_mc", i);
}else{
curr_item = curr_menu.attachMovie("menuitem1","item"+i+"_mc", i);
};

```

I need the for loop where it is as it assigns all the values to each clip down the bottom of the page.

At the moment im using the if statement to assign different clips depending on whether the item is a menu or a submenu item.

Any ideas how i would add a delay inbetween each of the attachmovies?

Here’s the whole as if it makes sense… [xmlmenu.fla.as](http://www.agimedia.net/temp_images/xmlmenu.fla.as)

---

<div class="post-metadata">

**Author:** ![flextnet](https://avatars.discourse-cdn.com/v4/letter/f/7ba0ec/32.png) [@flextnet](https://forum.kirupa.com/u/flextnet)\
**Post date:** [April 6, 2006, 1:41am UTC](https://forum.kirupa.com/t/delay-setinterval-with-attachmovie/184582/2 "2006-04-06T01:41:34Z")

</div>

How about something like this:

// for all items or XML nodes (items and menus)  
// within this node\_xml passed for this menu  
attach\_counter = 0;

// Now set the delay for 1 second  
delay = setInterval(attachCallback, 1000);

function attachCallback()  
{  
// movieclip for each menu item  
if (node\_xml.childNodes[attach\_counter].nodeName == “menu”){  
curr\_item = curr\_menu.attachMovie(“menuitem”,“item”+attach\_counter+"\_mc", attach\_counter);  
}else{  
curr\_item = curr\_menu.attachMovie(“menuitem1”,“item”+attach\_counter+"\_mc", attach\_counter);  
}

if (++attach\_counter \>= node\_xml.childNodes.length)  
{  
clearInterval(delay);  
}  
}

---

<div class="post-metadata">

**Author:** ![inVZbl](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/invzbl/32/309_2.png) [@inVZbl](https://forum.kirupa.com/u/inVZbl)\
**Post date:** [April 6, 2006, 2:36am UTC](https://forum.kirupa.com/t/delay-setinterval-with-attachmovie/184582/3 "2006-04-06T02:36:50Z")

</div>

thanks for the reply, tried it but it didnt seem to work though.

the preloader i have on the file just kept looping back to the start when i added in that code.

This is the fla file im using at the moment with most of the elements stripped out…

[URL=“[http://www.agimedia.net/temp\_images/flash.zip](http://www.agimedia.net/temp_images/flash.zip)”]  
flash.zip

---

<div class="post-metadata">

**Author:** ![flextnet](https://avatars.discourse-cdn.com/v4/letter/f/7ba0ec/32.png) [@flextnet](https://forum.kirupa.com/u/flextnet)\
**Post date:** [April 6, 2006, 2:58am UTC](https://forum.kirupa.com/t/delay-setinterval-with-attachmovie/184582/4 "2006-04-06T02:58:55Z")

</div>

Ok it looks like Preloader.as wasn’t included in the zip.

---

<div class="post-metadata">

**Author:** ![inVZbl](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/invzbl/32/309_2.png) [@inVZbl](https://forum.kirupa.com/u/inVZbl)\
**Post date:** [April 6, 2006, 4:01am UTC](https://forum.kirupa.com/t/delay-setinterval-with-attachmovie/184582/5 "2006-04-06T04:01:16Z")

</div>

> [@flextnet](#):
>
> Ok it looks like Preloader.as wasn’t included in the zip.

oops sorry about that, just updated the file with preloader as in it.

[flash.zip](http://www.agimedia.net/temp_images/flash.zip)

---

<div class="post-metadata">

**Author:** ![flextnet](https://avatars.discourse-cdn.com/v4/letter/f/7ba0ec/32.png) [@flextnet](https://forum.kirupa.com/u/flextnet)\
**Post date:** [April 6, 2006, 4:26am UTC](https://forum.kirupa.com/t/delay-setinterval-with-attachmovie/184582/6 "2006-04-06T04:26:10Z")

</div>

Well I can’t upload the fla because it’s too big, but here are the changes I made to the code… I added the AttachMenus function to handle callbacks from the timer.

// generates a list of menu items (effectively one menu)  
// given the inputted parameters. This makes the main menu  
// as well as any of the submenus  
GenerateMenu = function(container, name, x, y, depth, node\_xml) {  
// variable declarations  
var curr\_menu = container.createEmptyMovieClip(name, depth);

// for all items or XML nodes (items and menus)  
// within this node\_xml passed for this menu  
attachQ = new Array();  
for (var i=0; i\<node\_xml.childNodes.length; i++) {  
// movieclip for each menu item  
var mc = “menuitem”;  
if (node\_xml.childNodes\*.nodeName != “menu”){  
mc = “menuitem1”;  
}  
attachQ.push({idx: i, mcname: mc, node: node\_xml.childNodes\*, x: x, y: y});  
}

delay = setInterval(AttachMenus, 1000, curr\_menu);  
}  
AttachMenus = function(curr\_menu)  
{  
var curr\_node;  
var curr\_item;  
if (attachQ.length == 0)  
{  
clearInterval(delay);  
return;  
}  
var info = attachQ.shift();

curr\_item = curr\_menu.attachMovie(info.mcname,“item”+info.idx+"\_mc", info.idx);

curr\_item.\_x = info.x;  
curr\_item.\_y = info.y + info.idx\*curr\_item.\_height;

curr\_item.background.\_alpha = 0;  
tTasks.\_alpha = 40;  
tRoles.\_alpha = 40;

// item properties assigned from XML  
curr\_node = info.node;  
curr\_item.action = curr\_node.attributes.url;  
curr\_item.roles = curr\_node.attributes.roles;  
curr\_item.tasks = curr\_node.attributes.tasks;  
curr\_item.name.text = curr\_node.attributes.title;

// item submenu behavior for rollover event  
if (curr\_node.nodeName == “menu”){  
// open a submenu  
curr\_item.node\_xml = curr\_node;  
curr\_item.onRollOver = curr\_item.onDragOver = function(){  
tweenMenu(slider.\_y,this.\_y);  
GenerateMenu(curr\_menu, “submenu\_mc”, 315, 60, 1000, this.node\_xml);  
};

}else{ // nodeName == “item”

// close existing submenu  
curr\_item.onRollOver = curr\_item.onDragOver = function(){  
tasks.text = this.tasks  
roles.text = this.roles  
curr\_menu.submenu\_mc.removeMovieClip();

// show a hover color and show titles at full colour  
var menuTween:Tween = new Tween(this.background, “\_alpha”, Strong.easeOut, 0, 30, .5, true);  
var menuTween:Tween = new Tween(\_root.tTasks, “\_alpha”, Strong.easeOut, 40, 100, .5, true);  
var menuTween:Tween = new Tween(\_root.tRoles, “\_alpha”, Strong.easeOut, 40, 100, .5, true);  
};

curr\_item.onRollOut = curr\_item.onDragOut = function(){  
tasks.text = “”;  
roles.text = “”;  
// restore color  
var menuTween:Tween = new Tween(this.background, “\_alpha”, Strong.easeOut, 30, 0, .9, true);  
var menuTween:Tween = new Tween(\_root.tTasks, “\_alpha”, Strong.easeOut, 100, 40, .5, true);  
var menuTween:Tween = new Tween(\_root.tRoles, “\_alpha”, Strong.easeOut, 100, 40, .5, true);  
};

// any item, menu opening or not can have actions  
curr\_item.onRelease = function(){  
getURL(this.action);  
};

}  
};

---

<div class="post-metadata">

**Author:** ![inVZbl](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/invzbl/32/309_2.png) [@inVZbl](https://forum.kirupa.com/u/inVZbl)\
**Post date:** [April 6, 2006, 12:44pm UTC](https://forum.kirupa.com/t/delay-setinterval-with-attachmovie/184582/7 "2006-04-06T12:44:13Z")

</div>

Thanks so much for this it seems to be working like a charm…

Only one thing i have noticed with this is that, if the mouse is over one of the left hand buttons when its loading the menu item seem to stop up to that certain point. i.e if the mouse is accidently at the same point as where menu item 3 is nothing will show underneath it. Any ideas as to why that happens…

Again thank you so much for your help…

---

<div class="post-metadata">

**Author:** ![inVZbl](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/invzbl/32/309_2.png) [@inVZbl](https://forum.kirupa.com/u/inVZbl)\
**Post date:** [April 6, 2006, 12:51pm UTC](https://forum.kirupa.com/t/delay-setinterval-with-attachmovie/184582/8 "2006-04-06T12:51:11Z")

</div>

Just figured out that is caused by the second level menu generation function on the rollOver event

GenerateMenu(curr\_menu, “submenu\_mc”, 315, 60, 1000, this.node\_xml);

edit - IT ALL WORKS NOW.

Applied the generatemenu function when attachQ = 0, and its all sweet.

Thanks again
