Passing variables through setInterval

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?

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

:p:

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).

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.

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