如何在 AS3 中的影片剪辑中停止所有子影片剪辑? [英] How to stop all child movieclips inside a movieclip in AS3?
问题描述
我有一个影片剪辑,它是游戏中的一个角色.在这个影片剪辑中有几个包含有动画的肢体的影片剪辑.那么有人对如何 gotoAndStop(1); 有任何建议吗?无需手动调用每个肢体对象?
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 on how to gotoAndStop(1); on all the movieclips that are inside the character without having to call on every limb object manually?
角色影片剪辑在 4 帧上总共包含 20 个影片剪辑,因此我只想停止角色内的所有影片剪辑.
The character movieclip contains a total of 20 movieclips on 4 frames, so I just want to stop all of the movieclips inside the character.
推荐答案
如果我理解正确(即:停止另一个影片剪辑中的所有影片剪辑),这应该有效:
If i understand you correctly (ie: stop all movieclips within another movieclip), this should work:
function stopAllClips(mc:MovieClip):void
{
var n:int = mc.numChildren;
for (var i:int=0;i<n;i++)
{
var clip:MoviceClip = mc.getChildAt(i) as MovieClip;
if (clip)
clip.gotoAndStop(1);
}
}
就这样称呼它:
stopAllClips(yourMovieClip);
其中 yourMovieClip 是角色.
Where yourMovieClip is the character.
从 Flash Player 11.8/AIR 3.8 开始,所有 DisplayObjectContainer 都有一个内置方法,名为 stopAllMovieClips.
As of Flash Player 11.8 / AIR 3.8, there is a built in method for all DisplayObjectContainers called stopAllMovieClips.
commonParent.stopAllMovieClips();
请记住,这将递归地停止所有子代和孙代,这与仅停止直接子代的原始答案不同.
Keep in mind, this will recursively stop all children and grandchildren, unlike the the original answer which only stops the immediate children.
这篇关于如何在 AS3 中的影片剪辑中停止所有子影片剪辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!