开发者

Sprites are visible after removeChild is called

开发者 https://www.devze.com 2023-02-10 21:04 出处:网络
I have a container with children that needs to be replaced by other periodically. Those children are sprites and they have one weak referenced event listeners for MOUSE_DOWN event. When I call removeC

I have a container with children that needs to be replaced by other periodically. Those children are sprites and they have one weak referenced event listeners for MOUSE_DOWN event. When I call removeChild on children, numChildren from container decreases to 0 but they are still visible in flash. I even tried to remove container and recreate new one but it still doesn't work. Also tried to add 开发者_如何学Csome dummy simple sprite instead, without any event listeners but it didn't bring any results. I presume that garbage collector is not working as I wish :)

Here is my code for creating sprites:

itemHolder=new Sprite();
addChild(itemHolder);
itemHolder.y=itemHolderY;

var itemY:Number=0;

for(var i:Number=0;i<modelBarList.bars.length;i++){
    var item:bar_list_item;
    item=new bar_list_item();
    item.name="item"+i;
    /*
    setting properties for item
    */
    itemHolder.addChild(item);              
    item.y=itemY;
    item.mouseChildren=false;
    item.buttonMode=true;
    itemY+=item.height;
    item.addEventListener(MouseEvent.MOUSE_UP,barSelected,false,10,true);
}

And code for removing:

while(itemHolder.numChildren){
    var item:Sprite=Sprite(itemHolder.getChildAt(0));
    item.removeEventListener(MouseEvent.MOUSE_UP,barSelected,false);
    itemHolder.removeChild(item);
    item=null;
}
removeChild(itemHolder);
itemHolder=null;


I don't think it has anything to do with Garbage Collector. Are you 100% sure that the itemHolder in second code is the same as the itemHolder in the first? Perhaps you could try adding trace("Yep, this code executes") to the second snippet and see if it executes for sure? That, or the problem lies somewhere else in your code I think.

0

精彩评论

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