# Passing variables through setInterval

**URL:** <https://forum.kirupa.com/t/passing-variables-through-setinterval/184563>\
**Category:** Uncategorized\
**Created:** [April 5, 2006, 10:26pm UTC](https://forum.kirupa.com/t/passing-variables-through-setinterval/184563 "2006-04-05T22:26:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kame](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kame/32/2333_2.png) [@Kame](https://forum.kirupa.com/u/Kame)\
**Post date:** [April 5, 2006, 10:26pm UTC](https://forum.kirupa.com/t/passing-variables-through-setinterval/184563/1 "2006-04-05T22:26:41Z")

</div>

The goal is to loop through an array, create a setInterval function for each item in the array, passing that item to the setInterval.

Basic code looks like:  
setInterval(startClip, intervalTime, mcList\*)

This hasn’t worked. I’ve tried specifying a specific array item (mcList[0]) but to no avail. But when I put in the specific parameter, bypassing the array, it works fine. I tried passing the array item to a variable to designate what it was but this didn’t work either. So I’m guessing that setInterval can’t parse the parameter as a variable. Anyone know if there’s a way around this, or if I’m just doing something wrong?

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 5, 2006, 11:29pm UTC](https://forum.kirupa.com/t/passing-variables-through-setinterval/184563/2 "2006-04-05T23:29:29Z")

</div>

I’m pretty sure you’re doing something wrong, could you post the rest of your code?

:p:

---

<div class="post-metadata">

**Author:** ![Kame](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kame/32/2333_2.png) [@Kame](https://forum.kirupa.com/u/Kame)\
**Post date:** [April 5, 2006, 11:50pm UTC](https://forum.kirupa.com/t/passing-variables-through-setinterval/184563/3 "2006-04-05T23:50:18Z")

</div>

I’ve re-written it so many times I’m not really sure where I’m at, but this is what I have at the moment. To simplify things for the time being, I’ve taken out the loop and have just been trying to get the interval to work.

var mcList:Array = new Array(“storeServers\_mc”, “corpServers\_mc”, “endpoints\_mc”);

function startClip(clip) {  
var frameTotal:Number = clip.\_totalframes;  
var ranFrame:Number = random(frameTotal)+1;  
clip.gotoAndStop(ranFrame);  
}

var minTime:Number = 3000;  
var maxTime:Number = 5000;

function randRange(min:Number, max:Number):Number {  
var randomNum:Number = Math.floor(Math.random()\*(max-min+1))+min;  
return randomNum;  
}

var intervalTime:Number = randRange(minTime, maxTime);  
intervalID = setInterval(startClip, intervalTime, mcList[0]);

I can do a trace on mcList[0] and it spits out the right value. But there’s nothing to distinguish the parameter as a variable or object, so I’m guessing its not supported (hoping it is somehow).

---

<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, 3:17am UTC](https://forum.kirupa.com/t/passing-variables-through-setinterval/184563/4 "2006-04-06T03:17:26Z")

</div>

Looks to me like you’re trying to use a string as a movieclip object inside startClip()… you’re passing a string in mcList[0].

Maybe you should try:

var mcList:Array = new Array(storeServers\_mc, corpServers\_mc, endpoints\_mc);

assuming those mc’s are defined on the timeline.

---

<div class="post-metadata">

**Author:** ![Kame](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kame/32/2333_2.png) [@Kame](https://forum.kirupa.com/u/Kame)\
**Post date:** [April 6, 2006, 4:36pm UTC](https://forum.kirupa.com/t/passing-variables-through-setinterval/184563/5 "2006-04-06T16:36:53Z")

</div>

Ah, that was exactly it. Never even considered they might be strings. Thanks a bunch.
