Trying to figure out functions

Hey, I’m kind of a beginner here so bear with me. I’m trying to make camera flashes in a crowd with random locations and a random time between flashes. I made a function that works, but I’d really like to make it more reusable, so that I could have two flasher functions running at once. I’m having a lot of trouble figuring out how to reference just the instance created in the function, anyway here’s the code.



randomRange = function(min, max){
    return Math.floor(Math.random()*(max-min+1)) + min;
}

function flasher(){
    clearInterval(intName);
    _root.attachMovie("flash", "flash1", 10);
    rdmNum = randomRange(500, 3000);
    flash1._x = randomRange(10, 540);
    flash1._y = randomRange(10, 390);
    intName = setInterval(flasher, rdmNum); 
    //trace("1 = "+rdmNum);
}

flasher();


Any tips?

Ok, I figured out one part. I just need a way to give the interval a unique name so that each time it is calledit doesn’t interfere with the rest. Every time I try to make it unique it seems to break the clearInterval function. Ideas? Here’s what I have so far


randomRange = function (min, max) {
    return Math.floor(Math.random()*(max-min+1))+min;
};

function flasher(num) {
    clearInterval(interval);
    var t = _root.attachMovie("flash", "flash"+num, num+1);
    rdmNum = randomRange(500, 3000);
    t._x = randomRange(10, 540);
    t._y = randomRange(10, 390);
    interval = setInterval(flasher, rdmNum, num);
}

flasher(1);
flasher(2);

It’s probably easier if you don’t have to keep track of intervals at all:

function flasher(num) {
    var t = _root.attachMovie("flash", "flash"+num, num+1);
    rdmNum = randomRange(500, 3000);
    t._x = randomRange(10, 540);
    t._y = randomRange(10, 390);
    setTimeout(flasher, rdmNum, num);
}