How to stop all child movieclips inside a movieclip in AS3?

前端 未结 2 1298
-上瘾入骨i
-上瘾入骨i 2021-01-17 06:13

I have a movieclip which is a character in a game. Inside this movieclips there are several movieclips containing limbs that has an animation. So do anyone have a suggestion

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-17 07:07

    Easiest way I think :

    // MovieClip propotype function that stop all running clips (current and inside clips)
    MovieClip.prototype.stopAllClips = function():void {
        var mc:MovieClip = this;
        var n:int = mc.numChildren;
        mc.gotoAndStop(1);
        for (var i:int=0; i

    So it's recursive, and can be called from a MovieClip it-self:

    myMovieClip.stopAllClips(); // Stop the clip and inner clips
    

    EDIT

    As of Flash Player 11.8 / AIR 3.8, there is a built in method for all DisplayObjectContainers called stopAllMovieClips.

    commonParent.stopAllMovieClips();
    

提交回复
热议问题