2

I'm creating an actionscript custom itemRenderer, and I have:

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

Where do I put my removeEventListener when I'm done with the itemRenderer?

sch
  • 27,436
  • 3
  • 68
  • 83
stevemcl
  • 367
  • 1
  • 3
  • 11

2 Answers2

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
}
Michael Allan Jackson
  • 4,217
  • 3
  • 35
  • 45
Antonos
  • 573
  • 2
  • 10
0

You can remove the event listeners when Event.REMOVED is dispatched. But first, you should add an event listener to receive it.

sch
  • 27,436
  • 3
  • 68
  • 83