martedì, giugno 12, 2007

Stop and start ALL movieclips in a SWF

One of the coding puzzles that has eluded me since the dawn of time is how do you use a navigation button to stop everything not only on the main timeline, but also a movie clip’s timeline?

I just realized that a Flash guru I admire (senocular) solved the question back in 2003. It is possible using the functions shown below to loop through all of your movieclips and stop all of them or start all of them.

MovieClip.prototype.stopAll = function() {

    this.stop();

    for (var m in this) if (typeof this[m] == "movieclip" && this[m]._parent == this) this[m].stopAll();

};

MovieClip.prototype.playAll = function() {

    this.play();

    for (var m in this) if (typeof this[m] == "movieclip" && this[m]._parent == this) this[m].playAll();

};

       

Then, it’s simply a matter of using this line:

_root.stopAll();

Or

_root.playAll();

Note: this will need to be modified for ActionScript 3.