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
}