Greg Militello wrote:

What do I have done? Not a ton. I got stuck. Which is why I need you all. What is my problem(s)? Simply, events. I think I need to use a lot of event listeners to handle this well, but there does not appear to be a ton of doc on draggable/dropable events, and how to use them. I
Hi Greg

I've been doing something similar - not chess unfortunately - but something which required my code to know when a draggable was clicked. First of all I tried to hack into the dragdrop code to do this - but I've scrapped that now. Instead I'm simply registering my draggable objects into a a new class, and registering on click events to the draggable elements, pseudo code below:



chess = Class.create();
chess.prototype = {
initialize: function() {
this.pieces = new Array(); //array of draggable chess pieces (objects)
   },
   addPiece: function( draggableObject ){
       var found = false;
//check if the draggable has not yet been registered:
       this.pieces.each(function(piece) {
           if(draggableObject  == piece){
               found = true;
           }
       }
       if(found == false){
           this.pieces.push( draggableObject );
           this.eventMouseDown  = this.activate.bindAsEventListener(this);
Event.observe(draggableObject.element, "mousedown", this.eventMouseDown);
       }
   },

activate: function(event){
   var el = Event.element( event );
  alert('you clicked on a chess piece!');
}
}
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to