Friday 15 June 2012

javascript - Removing a wrapper function callback with removeEventListener -


I have this code, which drags a ball around a canvas on the click and drag.

  canvas Ed Event Listener ('museudown', function () Click on initiallyClickX = MAO.X; var initial click = mouse; start initialBallX = ball.x; var initialBallY = ball.y; canvas.addEventListener ('moussev', function () {OnMouseMove (initialClickX, initial click, mouse.x, mouse.A., initial ball, initial bell}}, false);}, false); Function OnMoiceMov (initialClickX, initialclick, mousex, mouse, initialball, initial bollywood) {ball.x = mousex + initialball - initialClickX; Ball.y = Mouse Y + Initial BallY - InitialClick; Attract (); }   

The problem is, when I can not find the ball to stop dragging the mousepop. I know that I need to add:

  canvas. Removévent listener ('mausomov', function) (onmysmov (initialclickx, initialclick, mouse.x, mouse, initial, initial ball) }, false);   

But because the function is in a cover, the above version has no effect and the ball remains with my cursor. Can anyone recommend some way around this?

Do not use an anonymous function to remove the references to the Event Listener function is required.

  canvas.AdventListner ('Masudown', function) {var initialClickX = mouse.x; Var initialClickY = mouse.y; StartitialBallX = ball.x; Var initialBallY = function wrapper (onMouseMove) (initialClickX, initial click, mouse.x, mouse.A., initial ball, initial bell)} canvas.AdventListener ('mausomov', cover, false); // Canvas after some time .removeEventListener ('mousemove', wrapper);}, false);    

No comments:

Post a Comment