2012-03-04 21 views

答えて

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 
}