Remove Event Listen on Scene Load

Hey guys, I am trying to remove an event listener from one scene

			document.addEventListener('mouseup', function_x);
		alert("Listener added");
		function function_x() {
            alert("Function called");

when loading another scene by

document.removeEventListener('mouseup', function_x);

Pretty simple actually, I thought... but I cant get this to work. It is adding the event listener but not removing it on scene load. Minimal example attached. Do you guys have any idea? (239.1 KB)

Just add the event listener to the element itself … or use

PS: I was following some of your questions on the forum in the recent days and saw that you work a lot with the window and document scope. You can do most things in the hypeDocument scope making the whole thing more "modular" and "localized".


@MaxZieb The thing is, that i dont have a special element, actually every click or swipe should reset a timer, so I wrote one function for all clicks.

But when it comes to a certain scene in the document, I would like to remove my event listener.

Isnt that possible to achieve?

It sure is… just query the scene name and return out of the event listener if (sceneName!='XYZ') return; if it isn't the scene you want (given you "know" sceneName on the window scope). Chris Ferdinandi has some nice reading on the general subject matter:

In contrast to his preferences I like to keep things local in Hype because I often use them as "Widgets" and can't rely on controlling window/document or might have the same widget twice on a page and want to avoid interferences.

1 Like

Hi Max thanks a lot, also for the idea of doing this with an onmouseup event. tried it and it does the trick for me. Thx again!