You need to bind the "this" object to your Ball object for the event
listener. Also, instead of using anonymous functions as page
initializers, I prefer to utilize named methods (so they can be more
easily extended/detached).

var Ball = {
  initialize: function(){
    this.ball = $('ball');
    this.ball.observe('click', this.appear.bindAsEventListener(this));
  },
  appear: function(event){
    if (this.ballAppeared)
      this.destroy();
    else
      this.create();
  },
  create: function(){
    this.ballAppeared = true;
    alert("Creating my ball from: " + this.ball);
  },
  destroy: function(){
    this.ballAppeared = false;
    alert("Destroying my ball from: " + this.ball);
  }
};
document.observe('dom:loaded', Ball.initialize.bindAsEventListener(Ball));

Have a great day.

-justin

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to