Koden
Koden

Reputation: 353

Looking for a way to stop ALL movieclips

I have a project with a LOT of symbols each playing at certain times. I would like a command to stop all symbols from playing without having to actually add mc.stop(); for every single one.

I have tried the generic stop(); but that doesnt work Anybody know anyway to easily do this?

Upvotes: 0

Views: 631

Answers (2)

BadFeelingAboutThis
BadFeelingAboutThis

Reputation: 14406

If you are using Flash Player 11.8 / AIR 3.8 or later, you can just use the built in stopAllMovieClips method.

Recursively stops the timeline execution of all MovieClips rooted at this object.

Usage:

commonParent.stopAllMovieClips();

Where commonParent is the top most object that contains all the MovieClip's you would like to stop. This could be the mainTimeline or stage if you truly wanted to stop everything.

If you only want to stop the immediate children of a parent, use the solution in the first part of payam sbr's answer.

Upvotes: 3

payam_sbr
payam_sbr

Reputation: 1426

you have to search all of existing child's of your container, then check if that's Movieclip stop its time-line

for example call movieClipStopAll(this) with this following function

function movieClipStopChilds(container:DisplayObjectContainer):void {
     for (var i:uint = 0; i < container.numChildren; i++)
        if (container.getChildAt(i) is MovieClip)
            (container.getChildAt(i) as MovieClip).stop();
}

Edit:

following function also stop inner child movieclips

function movieClipStopAll(container:DisplayObjectContainer):void {
     for (var i:uint = 0; i < container.numChildren; i++)
        if (container.getChildAt(i) is MovieClip) {
            (container.getChildAt(i) as MovieClip).stop();
            movieClipStopAll(container.getChildAt(i));
        }
}

Upvotes: 3

Related Questions