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 HttpServlet and GenericServlet?
  What are the common mechanisms used for session tracking? ?
  Explain the life cycle methods of a Servlet. ?
  How does JSP handle run-time exceptions? ?
  How do I prevent the output of my JSP or Servlet pages from being cached by the browser?
  Explain the life-cycle mehtods in JSP?
  What environment variables do I need to set on my machine in order to be able to run Java programs?
  Can a public class MyClass be defined in a source file named YourClass.java? ?
  What will be the default values of all the elements of an array defined as an instance variable?
  What is the difference between static and non-static variables?
  How does Java handle integer overflows and underflows?
  What is synchronization and why is it important?
  How do I dynamically disable/ enable form elements using JavaScript?
  How do I manipulate radio and check boxes in JavaScript?
Add New Question
Glossary
Add Glossary
 
Copyright © 2009-10 Krify Software Technologies Pvt Ltd. All rights reserved.