var frequency = 3;
this.bigButton.addEventListener("mouseover", mouseOverFunction);
this.bigButton.addEventListener("mouseout", mouseOutFunction); 

function mouseOverFunction() {
	canVas.addEventListener("mousemove", setMousePosition, true);
	function setMousePosition(e) {
	  mouseX = e.clientX - canvasPos.x;
	  mouseY = e.clientY - canvasPos.y;

	  context.arc(mouseX, mouseY, 50, 0, 2 * Math.PI, true);
	  context.fillStyle = "#FF6A6A";

function mouseOutFunction(){
	canVas.removeEventListener("mousemove", setMousePosition, true);

can anyone tell me why the removeEventListener doesn’t work here? this code is in an adobe animate html5 canvas project. what i’m trying to accomplish is have a movie clip follow the mouse when hovering over a button, and then on mousing out of the button, have the setMousePosition stop and the movie clip go away.

Seems to me like setMousePosition is only accessible inside mouseOverFunction. Perhaps you should declare it outside.

1 Like