开发者

Flash Movieclips children Lost

开发者 https://www.devze.com 2022-12-18 18:01 出处:网络
I have a empty movieclip container in which I add movieclips as children. But when I try to get the children it does not trace/return anything. Here is my code.

I have a empty movieclip container in which I add movieclips as children. But when I try to get the children it does not trace/return anything. Here is my code.

// 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: " + competencyContain开发者_如何学Cer[childName]);

}

The movieclips are made perfectly on screen and do not give an error. The above code runs. But does not show the

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


You should use the getChildByName function...

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


This seems to work:

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);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号