Clearing setInterval from a different function

Could someone help me understand how to clear the interval in this code? I’d also like to know if there is a better way of firing makeStars() than using setInterval in a function - like I’m doing. I’ve looked at the Kirupa tutorial and I’m not seeing what should be done.

Basically, this attaches a number of stars within the Stage width and height properties. When the browser resizes I rewrite the stars to the screen with the new bounds. But I can’t get the interval to stop, so the stars just keep getting replaced - disappearing and relocating abruptly.

It all works great outside of the resizeIt() function, but once inside she goes down hill from there. A couple of things I need cleared up (pun intended) are:

  1. Am I creating a new interval each time resizeIt() is executed?
    2.What is the scope of the interval(s), and does how you access them change depending on where you are in the code, or are they more global?

Thanks,
John

stop();
[COLOR=gray]//number of stars to make[/COLOR]
var numstars:Number = 100;

_root.attachMovie(“background”,“bkgd”,this.getNextHighestDepth());
var container = _root.createEmptyMovieClip(“mycontainer”,_root.getNextHighestDepth());
var w:Number = Stage.width;
var h:Number = Stage.height;
_root.mycontainer.lineStyle(1,0xFFFFFF,0);
_root.mycontainer.moveTo(0,0);
_root.mycontainer.lineTo(w,0);
_root.mycontainer.lineTo(w,h);
_root.mycontainer.lineTo(0,h);
_root.mycontainer.lineTo(0,0);
_root.mycontainer.endFill();

var n:Number = 0;
function [COLOR=red]makeStars()[/COLOR][COLOR=black]:[/COLOR]Void{
mycontainer.attachMovie(“mcStar”, “star”+n, n);
setProperty(mycontainer[“star”+n], _y, Math.random() * Stage.height);
setProperty(mycontainer[“star”+n], _x, Math.random() * Stage.width);
n++;
if(n == numstars){
[COLOR=gray]//need interval cleared here to stop calling makeStars() from resizeIt() function.[/COLOR]
[COLOR=red]clearInterval(intervalID);[/COLOR]
n = 0;
}
}

Stage.align = “TL”;
Stage.scaleMode = “noScale”;
function [COLOR=red]resizeIt()[/COLOR] {
_root.bkgd._width = Stage.width;
_root.bkgd._height = Stage.height;
_root.bkgd._x = _root.bkgd._width / 2;
_root.bkgd._y = _root.bkgd._height / 2;
bkgd.bwidth.text = Stage.width;
[COLOR=red]var intervalID:Number = setInterval(makeStars, 100);[/COLOR]
}
var stageL:Object = new Object();
stageL.onResize = resizeIt;
Stage.addListener(stageL);
resizeIt();

onEnterFrame = function(){
//Moves stars off of mouse position and screen wraps.
for(var x:Number=0; x<numstars; x++){
setProperty(mycontainer[“star”+x], _x, ((Stage.width/2 - _xmouse) * 0.03) + mycontainer[“star”+x]._x);
setProperty(mycontainer[“star”+x], _y, ((Stage.height/2 - _ymouse) * 0.03) + mycontainer[“star”+x]._y);

if(mycontainer[“star”+x]._x > Stage.width +25){
mycontainer[“star”+x]._x -= Stage.width + 50;
}
else if(mycontainer[“star”+x]._x < Stage.width - Stage.width -25){
mycontainer[“star”+x]._x += Stage.width + 50;
}
if(mycontainer[“star”+x]._y > Stage.height + 25){
mycontainer[“star”+x]._y -= Stage.height + 50;
}
else if(mycontainer[“star”+x]._y < Stage.height - Stage.height - 25){
mycontainer[“star”+x]._y += Stage.height + 50;
}
}
}