Remove event listener from another function

Hello!
I’ve added an event listener to a function:

document.addEventListener('mousemove', dragTimeline);

document.addEventListener('click', function(){
	document.removeEventListener('mousemove', dragTimeline);
})

function dragTimeline(e){
          hypeDocument.pauseTimelineNamed('Main Timeline')
          // other functions
	
}

In another function that runs on document load, I’ve got a timer function. When that timer function clears interval, I need to remove the event listener from the first function. My problem is I’m getting an error: “ReferenceError: dragTimeline is not defined[Learn More]”

if (seconds >= 7200) {
		
		clearInterval(time);
		document.removeEventListener('mousemove', dragTimeline);
		hypeDocument.goToTimeInTimelineNamed(0, 'Main Timeline');
		
	}

I know it’s because of scope of the first function reference. My question is how to I correctly reference the listener from the timer function. They need to be separated functions, I can’t just run the timer from the same function I created the listener in.

Thanks!

Please provide an example. You already seam very invested in the structure. Maybe the structure is the problem. What are you trying to actually do.

1 Like