Flash Movieclips儿童迷失

时间:2010-01-27 07:26:35

标签: flash actionscript-3

我有一个空的movieclip容器,我在其中添加了动画片段作为子项。但是当我试图让孩子们没有追踪/返回任何东西时。这是我的代码。

// Creating Container
var competencyContainer:MovieClip = new MovieClip();
competencyContainer.name = "competencyContainer";
this.addChild(competencyContainer);

var lastx:Number = 200;
function createUsers(){

// Creating movieclips
for (var i:Number=0; i<globals.scoreList.length;i++)
{
    var test:MovieClip = new userbox();
    test.x= lastx;
    lastx = lastx+104.3;    
    test.name = String(i);
    competencyContainer.addChild(test);
}

}

function moveRight(eventObject:MouseEvent){

trace("right Pressed");
trace(competencyContainer);
for(var childName in competencyContainer){
    trace("child movieclip: " + competencyContainer[childName]);

}

动画片段在屏幕上完美制作,不会出错。上面的代码运行。但是没有显示

trace("child movieclip: " + competencyContainer[childName]);

2 个答案:

答案 0 :(得分:1)

您应该使用getChildByName功能......

trace("child movieclip: " + competencyContainer.getChildByName(childName));

答案 1 :(得分:1)

这似乎有效:

function moveRight(eventObject:MouseEvent)
{

    trace("right Pressed");
    var test:Number = competencyContainer.numChildren;
    trace(competencyContainer.numChildren);
    for(var i:Number = 0; i < test; i++)
    {
      var children:DisplayObject = competencyContainer.getChildAt(i);
      trace(children.name);
    }
}