Question

I'm having same issue exactly explained in this forum post How to stop all child movieclips inside a movieclip in AS3?

Except my requirement is When user click the pause button current frame holding movie clip child element should gotoAndStop and 25 frame.

Also I'm using a timer function so when user click pause button timer should be stopped. This actually working when I add the following code myTimer.stop(); however if I clicked the play button I put this one myTimer.start();. The issue is from myTimer.start(); function it's actually starting the timer all over again but I need to resume the timer.

Could any help me out of these issues. ASAP

Was it helpful?

Solution 2

To stop all your child movieclips you could use the code provided in that answer you linked to in your question:

yourButton.addEventListener(MouseEvent.CLICK, onClick);

function onClick(e:MouseEvent):void {
    stopAllClips(yourMovieClip);
}

function stopAllClips(mc:MovieClip):void
{
    var n:int = mc.numChildren;
    for (var i:int=0;i<n;i++)
    {
        var clip:MovieClip = mc.getChildAt(i) as MovieClip;
        if (clip && clip.name != 'mc_2')
            clip.gotoAndStop(2);
    }
}

In order to 'resume` your timer you need to keep a variable so you can 'resume' again. Something like this:

var tempTimerCount:int = 0;
var timer:Timer = new Timer(1000);
timer.start();

And then when you want to stop:

tempTimerCount += timer.currentCount;
timer.stop();

And after start and you want to have the value of that timer you need to get the timer.currentCount + tempTimerCount;

Hope it helps.

OTHER TIPS

You can use recursion:

function stopAll(parent:DisplayObjectContainer){
    for(var i:int = 0; i < parent.numChildren; i++){
        var child = parent.getChildAt(i);        
        if(child.hasOwnProperty('stop')){
            child.stop();
        }
        if(child.hasOwnProperty('numChildren')){
            stopAll(child);
        }
    }
}

To assign to the button:

yourButton.addEventListener(MouseEvent.CLICK, onClick)

function onClick(e:MouseEvent){
    stopAll(youMainMovieClip);
}

Try this code it works 100%

Put this code in your main timeline and called using mouse event MovieClip_name.stopAllClips();

MovieClip.prototype.stopAllClips = function():void { var mc:MovieClip = this; var n:int = mc.numChildren; mc.stop(); for (var i:int=0; i<n; i++) { var clip:MovieClip = mc.getChildAt(i) as MovieClip; if (clip) { clip.stop(); clip.stopAllClips(); } } }

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top