Why are event listeners not deleted?

I have this in my constructor:

addEventListener(Event.REMOVED_FROM_STAGE, actualDestroy);

And this is actually Destroy:

    public function actualDestroy(e:* = null){
        removeEventListener(Event.REMOVED_FROM_STAGE,actualDestroy);
        if(this.parent){
            this.parent.removeChild(this);
        }
    }

The problem is that I get the error message: Error # 2094: event recursion overflow. Why does removechild continue to be called if this.parent does not exist? Why are event listeners not deleted?

+5
source share
1 answer

The name of the event is misleading. removedFromStage, according to the docs, "Dispatched when the display object is to be removed from the display list ." In other words, this is what happens in your code:

  • Somewhere in your code you call parent.removeChild(this)
  • actualDestroy . , this.parent != null
  • actualDestroy parent.removeChild(this).
  • 2

, , (, , ) , , , beingRemoved, , . parent.removeChild(this) actualDestroy.

+3

All Articles