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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh ChopraCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alg205Author Commented:
Thank you so much!!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.