Stop All Movies :: AS2 Helpful code
//enter the movieclip you wish to stop this will stop the movieclip and all nested instances
//e.g if we enter stopAllMovies(_root) this will stop every movieclip. Of course if you are wokring
//with levels and have external swfs, then you can use levels instead e.g
//stopAllMovies(_level5);
stopAllMovies(movieclip);
function stopAllMovies(movie:MovieClip):Void {
movie.stop();
for (var i:String in movie) {
if (movie[i] instanceof MovieClip) {
movie[i].stop();
stopAllMovies(movie[i]);
}
}
}
About Stopping All Movieclips:
This snippet builds upon the last 'banner' snippet. Sometimes you not only want to stop the banner from looping anymore, but you need to also stop all the movieclips which are playing as well. This kind of functionality is ideal for use of a recursion. The following script will stop all movieclips in their tracks(of course you need to make sure if any of the movieclips are running due by virtue of a setInterval on onEnterFrame you will have to clear or delete them):
Explanation:
We call the function stopAllMovies sending it a reference to a movieclip (i.e the movieclip which we wish to stop as well as all the nested movieclips within it ). We stop this movieclip and then we loop through each variable i within the movieclip and then check if movie[i] references a movieclip. If it does we stop this movieclip. Now since this is a movieclip it can contain more nested movieclips, hence we need to call the function again, sending it this movieclip as a reference, and the process repeats until we have stopped all the movieclips. Calling a function from within itself is called 'recursion'. The name sounds scarier than it is!! Many times newbies to flash use recursion without even knowing they are doing so!
3 comments:
hi guys
how to stop all movieclips means inside of movie clips at a single step for ex: symbol5, symbol6
Hi there, awesome site. I thought the topics you posted on were very interesting. I tried to add your RSS to my feed reader
and it a few. take a look at it, hopefully I can add you and follow.
Web Designer in New York
Hi,
Wow!
Truly a great post.
Thanks for such a great information. In these days its hard to find a honest blog about website design company new york
Post a Comment