Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to stop and resume the animations of nested movieclips

New Here ,
Sep 09, 2009 Sep 09, 2009

Hi


I have many nested movieclips  in different positions of the main timeline.


I have 2 buttons, play_btn and pause_btn.


I'd like when the user click pause_btn, the animations on the main timeline and in nested movieclips stop.


Whe he click play_btn the animations resume in both the main timeline and nested movieclips.



I have created array of nested movieclips on the main timeline.


var arr:Array = new Array(mc1, mc2, mc3, mc4, mc5);



play_btn.addEventListener(MouseEvent.CLICK, on_play_btn);
pause_btn.addEventListener(MouseEvent.CLICK, on_pause_btn);



function on_play_btn(e:MouseEvent):void
{
     gotoAndPlay(currentFrame);
    
     for(var i:Number = 0; i < arr.length; i++)
     {
         if(arr != null)
         {
             arr.play();
         }
     }
}


function on_pause_btn(e:MouseEvent):void
{
     gotoAndStop(currentFrame);
    
     for(var k:Number = 0; k < arr.length; k++)
     {
         if(arr != null)
         {
             arr.stop();
         }
     }
}


but it only stops the animations on the main timeline and dosen't stop the animations in the nested movieclips.


Help me Please.

TOPICS
ActionScript
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 09, 2009 Sep 09, 2009

You probably need to add the full path to each of the nested movieClips. You can get this by using the target tool in the Actions window.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 09, 2009 Sep 09, 2009

Could you please provide a sample of code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 09, 2009 Sep 09, 2009

You should only have to change the references in your array. You have: var arr:Array = new Array(mc1, mc2, mc3, mc4, mc5);

So, let's say that the first item, mc1, is the clip in the current timeline and the others are clips nested further in the movie's structure. You would then need to change mc2 to something like clipName.mc2, if that movieClip is nested two clips down. Just select the individual movieClip reference in the array and then use the target tool at the top of the Actions window and drill down to the movieClip that you want to reference. Then click OK and Flash will add the path to your array. Do this for each movieClip reference that you need to change.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 09, 2009 Sep 09, 2009

You can attempt to stop all the children recursively. Something like that:

function on_pause_btn(e:MouseEvent):void
{
    gotoAndStop(currentFrame);

    for(var k:Number = 0; k < arr.length; k++)
    {
        if(arr is MovieClip) stopAll(arr);
    }
}

function stopAll(mc:MovieClip) {
    mc.stop();
    for (var j:int = 0; j < mc.numChildren; j++) {
        if (mc.getChildAt(j) is MovieClip) stopAll(mc.getChildAt(j));
    }
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 09, 2009 Sep 09, 2009

I had this error:

1118: Implicit coercion of a value with static type flash.display:DisplayObject to a possibly unrelated type flash.display:MovieClip.    if (mc.getChildAt(j) is MovieClip) stopAll(mc.getChildAt(j));

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 09, 2009 Sep 09, 2009

Try:

if (mc.getChildAt(j) is MovieClip) stopAll(MovieClip(mc.getChildAt(j)));

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 09, 2009 Sep 09, 2009

The error disappeared but the animations in the nested movieclips are not stopped.


Thanks alot for helping me.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 09, 2009 Sep 09, 2009

What kind of animations are in the nested clips. Are they timeline animations or scripted ones?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 09, 2009 Sep 09, 2009

Timeline animations.


Motion Tween in flash CS4 (not classic Tween).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 09, 2009 Sep 09, 2009

I'm having the same issue.I have a main timeline, which has nested movieclips with there own timelines and motion tweens. Using the new motion tween, and not the classic tween, which may or may not be the problem.

Was having a similar issue with stopping the timeline, the main timeline would stop, but the nested movieclips would keep going. Found this blog post that helped.

http://blog.nobien.net/2009/02/05/as3-stopping-all-timeline-animations/

Used the code below to stop everything by passing the stage as the displayObject. Worked great, but now i'm having the reverse issue. When I resume play, the nested movieclip timeline stays exactly where I stopped it, and the main timeline resumes play. If there are a 100 frames in the nested movieclip, once it reaches the 101st frame, the main timeline kicks in again.


function stopAllChildMovieClips(displayObject:DisplayObjectContainer):void{
   
        var numChildren:int = displayObject.numChildren;
       
        for (var i:int = 0; i < numChildren; i++) {
           
            var child:DisplayObject = displayObject.getChildAt(i);
           
            if (child is DisplayObjectContainer) {
                if (child is MovieClip) {
                   
                    MovieClip(child).stop();
                       
                    }
                    stopAllChildMovieClips(DisplayObjectContainer(child));
                }
            }
           
           
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 09, 2009 Sep 09, 2009

Pezzomon, Thank you so much.

It worked perfect!

To resume the play, create the same function but change its name and pass the stage to it.

Here is the function:

function playoAllChildMovieClips(displayObject:DisplayObjectContainer):void{          

var numChildren:int = displayObject.numChildren;


       
        for (var i:int = 0; i < numChildren; i++) {
           
            var child:DisplayObject = displayObject.getChildAt(i);
           
            if (child is DisplayObjectContainer) {
                if (child is MovieClip) {
                   
                    MovieClip(child).play();
                       
                    }
                    playoAllChildMovieClips(DisplayObjectContainer(child));
                }
            }
           
           
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 09, 2009 Sep 09, 2009
LATEST

Thanks, I was about to post the same thing. Glad you figured it out as well.

Cheers.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines