Time for action – Using DOM level 2 events
In level 2, there is a function named removeEventListener
(detachEvent
is the equivalent of it in Internet Explorer's model).
This function allows one to remove an event listener. It only needs the type of the event (as a string) and the listener to be removed.
Unfortunately, every time you pass a reference to a function, the haXe compiler creates a closure. Closures are like functions enclosing functions and as such, the reference you pass to addEventListener
and the one you pass to removeEventListener
will never be equal, resulting in the removeEventListener
function not being able to remove the listener.
This can be tested in a very simple way.
Create an HTML file with the markup for two buttons and load our code as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <...