I''ve been using the bindAsEventListener function and registering
various events I want to monitor and have had some problems which
might be of interest.
First I have been having a crash on Safari 2.0 and 2.0.1. The
logical place to call Event.stopObserving to de-register the listener
is actually within the listener once it has finished its task. eg
register a mouseup listener from the mousedown event listener and
then remove the mouseup listener from within the mouseup listener
when the mouseup has executed.
I found that if Event.stopObserving was called as anything other than
the last line of the method, Safari would crash occasionally. Not
always but say about one time in twenty, sometimes on the second or
thrid click sometimes after forty or more clicks. I can only assume
that Safari is garbage collecting the method as soon as it is de-
registered even if it is still executing.
Second I was testing on Firefox. I wanted to monitor mouseover,
mousemove, mouseout and mouseup. There was a lot of commonality to
the code so I made a single binding of my handler object to the
handler method and test for the event.type to handle any differnce
for event type. The binding was like
this.myboundhandler = this.handlermethod.bindAsEventListener(this);
and then registering this.myboundhandler four times (once for each of
the above events). Safari and IE6 seemed to be OK with this but
Firefox was not so happy. Mainly it was not giving me all the
events, as if one listener had bumped off the others. Making four
separate bindings and registering them for the different events
seemed to get things going again.
this.myboundhandler1 = this.handlermethod.bindAsEventListener(this);
this.myboundhandler2 = this.handlermethod.bindAsEventListener(this);
...
Event.observe(document, "mouseout", this.myboundhandler1);
Event.observe(document, "mousemove", this.myboundhandler2);
...
But even after all that it only seemed to give me all the events (the
mouseup seemed to get lost the most) if I registered them in the
order: mouseover, mousemove, mouseout and mouseup. Register them as
mouseover, mousemove, mouseup and mouseout and I get no mouseups again.
Hopefully that will save someone some time. If anyone else has
similar experience do share.
Toby