?
Solved

How do I stop a looping function in actionscript 2.0

Posted on 2008-11-19
2
Medium Priority
?
1,019 Views
Last Modified: 2013-11-11
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

0
Comment
Question by:alg205
2 Comments
 
LVL 34

Accepted Solution

by:
Aneesh Chopra earned 500 total points
ID: 22994903
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
 

Author Closing Comment

by:alg205
ID: 31518255
Thank you so much!!!!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question