How to remove all event listeners from a display object?

后端 未结 5 924
天涯浪人
天涯浪人 2021-02-08 15:21

Is there a way to determine which event listeners are registered with a display object? I want to remove all event listeners from a display object so that I can assign new ones

5条回答
  •  滥情空心
    2021-02-08 15:47

    jeceuyper is right ...

    a side not though: DisplayObject extends EventDispatcher, which already does implement IEventDispatcher ... so to be more precise: you need to override addEventListener and removeEventListener to keep track of the listeners ...

    a few technical details: i suggest you use Dictionary to store the handler functions ... a bit slower for insertion, but much faster for removal ... also, Dictionary supports weak references, which is quite important in the case of event handling ... also keep in mind, that useCapture allows to add the same handler twice ...

    good luck then ... ;)

提交回复
热议问题