0

Helo, i have a prototyped function that I would like to use as a mouse movement handler, the code that i have right now looks like this

window.onmousemove=this.seeThings;
MainMenu=function(game)
{
  this.game=game;
  this.gb=new GuiButton(300,100,200,30,"haha",this.game);

}
MainMenu.prototype.draw=function()
{
  this.game.context.fillStyle="red";
  this.gb.draw();
}
MainMenu.prototype.seeThings(e)
{
  mouseX=e.clientX;
  mouseY=e.clientY;
  console.log(mouseX+"and"+mouseY);
  this.gb.seeHover(e);
 }

this code errors as: Uncaught ReferenceError: e is not defined MainMenu.js:13 (anonymous function) MainMenu.js:13

and no mouse motion is detected. how could I possibly make this work?

Rando Hinn
  • 1,255
  • 19
  • 41
  • Correct with this: `MainMenu.prototype.seeThings = function(e) {...};` that's just a syntax error - and, for the first line, you're assigning an undefined function to the handler, since `this` refers to `window`, and `window.seeThings` is undefined. Maybe you wanted to write that line inside the `MainMenu` *constructor*? – Niccolò Campolungo Jan 16 '14 at 12:18
  • so that line is correct, aye? wellp, i made this change: http://pastebin.com/SM0kKiCW which will complain on the MainMenu.prototype.seeThings = function(e) {...}; line that e is still undefined.. – Rando Hinn Jan 16 '14 at 13:35
  • It is still `MainMenu.prototype.seeThings(e)` – Niccolò Campolungo Jan 16 '14 at 14:18
  • First you should fix your syntax error and then you probably want to set mouseover to a closure instead of the function or you'll have trouble with the value of 'this'http://stackoverflow.com/a/16063711/1641941 – HMR Jan 16 '14 at 15:28
  • ahh, that, the Corrwct with this lead me to believe that line was correct as it was in my code :D – Rando Hinn Jan 16 '14 at 15:54

0 Answers0