How do I stop a looping function in actionscript 2.0

Hey all! I am a complete newbie when it comes to actionscripting. I followed a tutorial that creates falling snowflakes. The movie works fine by itself but my problem comes in when I copy the movie as a scene into another flash that has individual scenes as "commercials." When I run the movie, the snowflakes continue to fall throughout the other scenes. I know that I somehow have to stop the loop but I'm not sure how. I want it to just play for that scene (I have the background set to stop at 180 frames) I've tried looking at other posts and searching the internet and I think that I need to use clearInterval but I'm not sure where to put it or the exact syntax of how to write it. I understand what is written but not how to change it.

Any help is GREATLY appreciated!!! Thanks!!!


Here is my code:
 
this.createEmptyMovieClip("canvas_mc",10);
var i = 0;
 
myInterval = setInterval(addFlake,500);
 
function addFlake() {
if (i<20) {
var t:MovieClip = canvas_mc.attachMovie("snowflake","flake"+i,canvas _mc.getNextHighestDepth());
i++;
t._xscale = t._yscale = Math.random()*80+20;
t._x = Math.random()*Stage.width;
t._y = -50;
t._alpha = Math.random()*40+50;
}
}

Open in new window

alg205Asked:
Who is Participating?
 
Aneesh ChopraConnect With a Mentor Commented:
below is the udpate code,
I have added a new function "stopSnow", just call this function on a frame or whenever you want to stop the snow
this.createEmptyMovieClip("canvas_mc",10);
var i = 0;
 
myInterval = setInterval(addFlake, 500);
 
function addFlake() {
	if (i<20) {
		var t:MovieClip = canvas_mc.attachMovie("snowflake", "flake"+i, canvas_mc.getNextHighestDepth());
		i++;
		t._xscale = t._yscale=Math.random()*80+20;
		t._x = Math.random()*Stage.width;
		t._y = -50;
		t._alpha = Math.random()*40+50;
	}
}
 
 
function stopSnow() {
	clearInterval(myInterval);
	canvas_mc.removeMovieClip();
}

Open in new window

0
 
alg205Author Commented:
Thank you so much!!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.