2012-03-04 73 views
2

我創建ActionScript定義ItemRenderer,我有:如何刪除ItemRenderer中的EventListener?

override protected function createChildren():void { 
     super.createChildren(); 
     addEventListener(MouseEvent.CLICK, clicked,false,0,true); 
} 

我在哪裏把我的removeEventListener當我用的itemRenderer做了什麼?

回答

0

當調度Event.REMOVED時,您可以刪除事件偵聽器。但首先,您應該添加一個事件偵聽器來接收它。

1
override protected function createChildren():void { 
     super.createChildren(); 
     addEventListener(Event.ADDED_TO_STAGE, activateDeactivate, false, 0, true); 
     //will be removed by GC due to weak reference 
} 

private function activateDeactivate(evt:Event):void 
{ 
    switch(evt.type) 
    { 
     case Event.ADDED_TO_STAGE: 
      addEventListeners(); 
      break; 
     case Event.REMOVED_FROM_STAGE: 
      removeEventListeners(); 
      break; 
    } 
} 

protected function addEventListeners():void 
{ 
    addEventListener(Event.REMOVED_FROM_STAGE, activateDeactivate, false, 0, true); 

    //add all other event listeners here or override this method in your class 
} 

protected function removeEventListeners():void 
{ 
    removeEventListener(Event.REMOVED_FROM_STAGE, activateDeactivate); 

    //Remove all other event listeners here or override this method in your class 
} 
相關問題