如何将MovieClip实例添加到多个影片剪辑并迭代MovieClip父级的子项?

时间:2014-03-08 20:54:13

标签: actionscript-3 flash

var mainmc:MovieClip;
var mc1:MovieClip;
var mc2:MovieClip;
var mc3:MovieClip;
var lastmc:MovieClip;

mainmc.addChild(mc1);
mainmc.addChild(mc2);
mainmc.addChild(mc3);

mc1.addChild(lastmc);
mc2.addChild(lastmc);
mc3.addChild(lastmc);

for(var i=1; i<4; i++){ 
  mainmc.?????.lastmc.visible=false;
}

我需要在问题上写下什么?

1 个答案:

答案 0 :(得分:0)

无。您不能同时向多个父母添加相同的MovieClip lastmc。从您的代码中,lastmc将只在mc3

如果您想迭代mainmc的孩子:

var i: uint, len: uint = mainmc.numChildren, movie:MovieClip;

for(i; i < len; ++i){
    movie = mainmc.getChildAt(i) as MovieClip;
    if(movie != null && movie.numChildren > 0){
        movie.getChildAt(0).visible = false;
    }
}