Keith Hughitt wrote:
> Could anyone help tell me what I'm missing?
> 
> I could have sworn Prototype already had something like this (a
> function that fires only once and then removes itself), but I couldn't
> find it anywhere so I went about writing the code myself.
> 
> First I tried to do it by intuition using several variations of:
> 
> Event.observe(myNode, 'click', function(e) {
>       /** do stuff **/
>       Event.stopObserving(this);
> });
> 
> 
> After reading up a little more about "stopObserving" in the API, I
> gave it another stab:
> 
> var handler = function(e) {
>       /** do stuff **/
>       Event.stopObserving(myNode, 'click',
> handler.bindAsEventListener(this));
> };
> 
> Event.observe(myNode, 'click', moveOnce.bindAsEventListener(this));
> 
> But the event-handler is still called after the first click.
> 
> Any suggestions?
> 
> Thanks,
> Keith

If you are using prototype 1.6, you can call stopObserving with 1, 2, or
3 arguments.

Event.stopObserving(this) should remove all event handlers on the element
Event.stopObserving(this, 'click') should remove all click event
handlers on the element
Event.stopObserving(this, 'click', function) should just remove the one
handler.  With this, you need to make sure the function is exactly like
the one you used when you called observe.  This would be the function
that is returned when you called moveOnce.bindAsEventListener(this).

Earlier versions of prototype only handle the call with 3 arguments
passed in.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to