Actionscript – as2: Stop Movieclip within a movieclip

actionscriptactionscript-2flash

I have a movieclip called "main", inside of that I have all my layers and tweens, within another movieClip in those layers I have yet another movieClip which I wish to stop playing when the second movie clip has played 3 times.

movieClips:
main > trampoline > boyBounce

I have to code to stop the second "main" MC, but not the "boyBounce" one.

When the "main" MC have played 3 times It calls commands to gotoAndStop, I need a command I can call to stop/or goto the first frame of "boyBounce".

Ive tried:

_root.boyBounce.gotoAndStop("bounce_stop");
boyBounce.stop();
_level0.boyBounce.gotoAndStop("bounce_stop");

"bounce_stop" is the name of the first frame in "boyBounce".

Cheers

EDIT: I'll settle for a command that will stop ALL movieClips playing.

Best Answer

If you want to stop the boyBounce movie at the first frame. this code helps you

_root.main.trampoline.boyBounce.gotoAndStop("bounce_stop");

Or, if you want to stop the trampoline movie at any of the desired frame then this one helps you

 _root.main.trampoline.gotoAndStop(FRAME_NUMBER);

Or, if you want to simply stop the animation of trampoline then

_root.main.trampoline.stop();

or boyBounce

_root.main.trampoline.boyBounce.stop();

BTW, you can trace the thing which doesn't works in the correct direction. For example, in your code if you are trying to trace _root.boyBounce or boyBounce or _level0.boyBounce it logs null. Because there is no movie with the name boyBounce in the stage. Take care on object scope.

FYI, If you want to access any movieclip from the stage you should access via it's parent, you can't access the child directly unless you are accessing from the same level.

Always remember to access like PARENT_NAME.PARENT_NAME.CHILD_NAME. Also don't forget if you don't add _root in the front then it's start from the level you have ur code and it searches the movie with name PARENT_NAME in that level and returns null if there is no movie in that name.

Related Topic