Ask a Question    Search Answers  

Category
Computers >> Programming Concepts >> Java

Question
How to remove the event listener?  (1 answers) Posted by: venkatreddy04   Ask a Friend

Answers
1.

;it’s useful in situations where you want to stop listening after the first event has fired, for example. You can use it when the listener is an anonymous inner function, if you don’t know the type of the event, if the dispatcher is unknown or any combination of these.

Most of the time using weak references is probably more appropriate, but in some situations the snipplet above is handy.

A more complete example:

function registerHandler( handler : Function ) : void {
  dispatcher.addEventListener("somethingChanged", handler);
}

// ...

registerHandler(somethingChangedHandler);

// ...

function somethingChangedHandler( event : Event ) : void { event.currentTarget.removeEventListener(event.type, arguments.callee);

performActionInResponseToEvent(); }

If we assume that the three parts of the code above are separated so that the first and the last don’t know about each other, but the middle part knows about both, we can see that the generic way of removing an event listener is more or less the only way to do it.
    Answered by: nvreddy


    Add an Answer to this Question
    Add a New Question
    Notify updates to this question
    Mail to a Friend
Rate this answer:       Exact       Correct       somewhat correct       wrong       spam

User comments


  What is the difference between doPost and doGet methods?
  How are Servlets and JSP Pages related?
  Give the Details of XML files used in Validator Framework?
  What is ActionForm?
  What are the types of resultsets?
  What are the standard isolation levels defined by JDBC?
  How can I enable session tracking for JSP pages if the browser has disabled cookies?
  What's a better approach for enabling thread-safe servlets and JSPs? ?
  How do I use a scriptlet to initialize a newly instantiated bean? ?
  Is servlet is used to create a dynamic webpage or Static webpage or both?
  What is default capacity of connection pool objects in pool of app-server Weblogic and Tomcat webserver?
  Can we apply multiple inheritence in java?
  How to define an Abstract class?
  What is similarities/difference between an Abstract class and Interface?
Add New Question
Glossary
Add Glossary
 
Copyright © 2009-10 Krify Software Technologies Pvt Ltd. All rights reserved.