문제

다른 아이들이 주기적으로 교체 해야하는 컨테이너가 있습니다.그 아이들은 Sprites이며 마우스 _Down 이벤트에 대해 약한 참조 된 이벤트 리스너가 하나 있습니다.아이들의 remazechild를 호출 할 때, 컨테이너의 숫자가 0으로 감소하지만 여전히 플래시에서 볼 수 있습니다.조차도 컨테이너를 제거하고 새로운 것을 다시 만들려고했지만 여전히 작동하지 않습니다.또한 이벤트 리스너 없이는 대신 더미 간단한 스프라이트를 추가하려고했지만 결과가 발생하지 않았습니다.나는 가비지 수집가가 제가 원하는만큼 작동하지 않는다고 가정합니다.)

여기에 스프라이트 생성을위한 코드가 있습니다.

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

및 제거 코드 :

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top