Got the event working, but I can't figure out how to detach.

var TestEventObj = new Class({

        initialize: function(element) {
                this.element=$(element);
                this.attach();
        },

        testEvent: function(event){
                console.log(event.page.x);
        },

        attach: function(){
                this.element.addEvent('mousemove',this.testEvent);
                this.element.addEvent('click',this.detach);
        },

        detach: function(){
                this.element.removeEvent('mousemove',this.testEvent);
        }

});

In detach() I get ::  TypeError: Result of expression
'this.element' [undefined] is not an object.

On Jul 6, 4:11 pm, Ryan Florence <[email protected]> wrote:
> So I've got this stuff in a class
>
>         startMove: function(el){
>                 el.addEvent('mousemove',this.move(el,event));
>         },
>
>         move: function(el,event){
>                 el.setStyles({
>                         'left': event.page.x-(el.getSize().x/2),
>                         'top': event.page.y-(el.getSize().y/2)
>                 });
>         },
>
>         stop: function(el){            
>                 el.removeEvent('mousemove',this.move);
>         }
>
> But it doesn't work ... Result of expression 'event' [undefined] is  
> not an object.
>
> I know there's a syntax thing going on here.  How do I send that event  
> object into the move function?
>
> I had this working when the whole move function's code was nested  
> inside the startMove function.  But then I couldn't remove the event.
>
> Thanks!
>
> Ryan Florencehttp://ryanflorence.com/blog/

Reply via email to