Walter,
The poster who directed you to using event vs this is correct. I
didn't look at the syntax specifically provided, but here is an
excerpt from a real world example that I wrote:
This is inside of a custom object, so some of the syntax might be
slightly different than what you would need.
setupLink:function() {
var myLink = new
Element('A').setStyle({'cursor':'pointer'}).update('remove');
myLink.observe('click', this.removeRow);
},
removeRow:function(e) {
e.element().up('TR').remove();
e.stop();
}
The important part here is that when you're using Event.observe, it
passes the actual event as the first argument to the callback
function. The 'this' keyword probably isn't a concern in your case,
so you shouldn't need to use bind or bindAsEventListener. You should
instead be using whatever name you gave to the event in the definition
of your function. In my case, 'e'. If you do not use bind or
bindAs..., this will refer to the A(nchor) element that was clicked.
Only use bind or bindAs... if you need to change what 'this' refers
to. A great tool for figuring out what this refers to is firebug in
firefox 2.
As I mentioned, my example is within a custom object, but my callback
function isn't using 'this' to modify my object, so I have no need to
use bindAsEventListener. If I wanted 'this' to refer to my custom
object, then my observe call would have looked like this:
myLink.observe('click',
this.removeRow.bindAsEventListener(this));
Hope that helps,
Knox
On Mar 7, 8:08 am, Walter Lee Davis <[EMAIL PROTECTED]> wrote:
> Okay, I get that so far, but what is the name of the event that is
> automatically passed as the first parameter? One of the other posters
> suggested I use event.stop(), but that just got me an error as event
> was not defined.
>
> Walter
>
> On Mar 7, 2008, at 9:58 AM, T.J. Crowder wrote:
>
>
>
> > Unless you really want "this" to reference a string object within your
> > handler, you won't want to pass strings into bindAsEventListener as
> > far as I can see.
>
> > The first parameter to bindAsEventListener is the object that you want
> > to access via "this" within the handler (http://www.prototypejs.org/
> > api/function/bind,http://www.prototypejs.org/api/function/
> > bindAsEventListener).
> > When the handler is called in response to an event, the first argument
> > to it will be the event object for the event. These are two separate
> > things.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---