Copy link to clipboard
Copied
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
{
arr
}
}
}
but it only stops the animations on the main timeline and dosen't stop the animations in the nested movieclips.
Help me Please.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Could you please provide a sample of code.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
}
}
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));
}
}
Copy link to clipboard
Copied
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));
Copy link to clipboard
Copied
Try:
if (mc.getChildAt(j) is MovieClip) stopAll(MovieClip(mc.getChildAt(j)));
Copy link to clipboard
Copied
The error disappeared but the animations in the nested movieclips are not stopped.
Thanks alot for helping me.
Copy link to clipboard
Copied
What kind of animations are in the nested clips. Are they timeline animations or scripted ones?
Copy link to clipboard
Copied
Timeline animations.
Motion Tween in flash CS4 (not classic Tween).
Copy link to clipboard
Copied
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));
}
}
}
Copy link to clipboard
Copied
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));
}
}
}
Copy link to clipboard
Copied
Thanks, I was about to post the same thing. Glad you figured it out as well.
Cheers.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now