Need help

Hi

Is there possible with a command to stop all movieclips on the scene ??

Need help real fast…


MovieClip.prototype.stopAll = function(){
	this.stop();
	var obj;
	for (obj in this) if (typeof this[obj] == "movieclip") this[obj].stopAll();
}

_root.stopAll();

thanks for the fast answer

How do I get the movieclips startded again then ? =) (I´m sorry for my bad knowledge in Flash)


MovieClip.prototype.playAll = function(){
	this.play();
	var obj;
	for (obj in this) if (typeof this[obj] == "movieclip") this[obj].playAll();
}

_root.playAll();

:stuck_out_tongue: :stuck_out_tongue:

I should note if you have any variables in movieclips referencing another movieclips higher in the heirarchy, you’ll get caught in an infinite loop and flash will eventually exit the script (yes flash will exit it automatically because it uses recursion and Flash stops after 256 recursive calls).

I didnt think it would be a problem so I didnt include a check for that. An easy way is just to include something like

if (typeof this[obj] == “movieclip” && this[obj]._parent == this)

which will work 99% of the time, but _parent isnt read only, meaning you can change it to be whatever you want, and if you make it say, _root, then you get caught in that loop again. So instead a safer technique is


MovieClip.prototype.stopAll = function(){
	this.stop();
	var obj;
	for (obj in this){
		if (typeof this[obj] == "movieclip"){
			var ttarg = (this._target != "/") ? this._target : ""; // "" for _root
			var otarg = this[obj]._target.substr(0,this[obj]._target.lastIndexOf("/")); // objs _parent's target
			if (ttarg == otarg) this[obj].stopAll();
		}
	}
}

which seems a little overkill… and is more than likely completely unnecessary as long as you dont try to reassign the _parent property of movieclips