2 Replies Latest reply on Jun 11, 2008 11:47 AM by webvalue

    addEventListener again and again

    webvalue Level 1

      I know for sure that it is a good practice to remove a listener when it is not going to be used anymore. However, will addEventListener cause any problem if the same event has been added to a listener already? And how?

      hasEventListener can be used to detect whether an event has been added to a listener but I don't know how many times it has been "added".

        • 1. Re: addEventListener again and again
          m_hartnett Level 3
          The documentation specifies what happens very well. Take a look at any object that has the addEventListener method. here is the part that answers your question.

          After the listener is registered, subsequent calls to addEventListener() with a different value for either type or useCapture result in the creation of a separate listener registration. For example, if you first register a listener with useCapture set to true, it listens only during the capture phase. If you call addEventListener() again using the same listener object, but with useCapture set to false, you have two separate listeners: one that listens during the capture phase, and another that listens during the target and bubbling phases.

          • 2. Re: addEventListener again and again
            webvalue Level 1
            In my case, I am not using useCapture. Simply:

            aService.addEventListener(ResultEvent.RESULT, serviceResultHandler);

            Will multiple use of this statement without removing it using removeEventListener cause any problem?