Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.javascript Subject: Re: Stop the mouse listener Date: Thu, 24 Sep 2020 10:14:04 +0200 Lines: 60 Message-ID: References: <8zsym7odbn9r.1b62v3cn8pck0$.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net AWABC9m+iq1VnI1/29tOpwNPIGsn6bowQSXrIwg6fUeyWCs7Lq Cancel-Lock: sha1:KBUq4/h200KeCLOMQ4cFca325e8= In-Reply-To: Xref: csiph.com comp.lang.javascript:38837 Jonas Thörnvall: > Den onsdag 23 september 2020 kl. 13:49:32 UTC+2 skrev JJ: >> On Wed, 23 Sep 2020 00:16:47 -0700 (PDT), Jonas Thörnvall wrote: >>> I want to stop the mouse listener while player scroll thru moves >>> previous "board locked for moves". But i do not manage to turn >>> listener off. I can see the alert but the listener still run so >>> board never lockdown? >>> >>> function stop_listeners() { alert("test"); >>> c.removeEventListener('mouseup', start_listener); >>> c.removeEventListener('mousedown', start_listener); >>> c.removeEventListener('mousemove', start_listener); } >>> >>> // Start listener function start_listener() { mousePos = [0, 0]; >>> mouseDown = [0, 0]; mouseUp = [0, 0]; >>> c.addEventListener("mouseup", function(evt) { >> [snip] >> >> You never did stop the listeners. `start_listener` is not even used >> as an event handler. > > I am not sure what you do say JJ, that if i call function > start_listener it have not started the listeners, how come they work > then. I just ask for howto remove them...? You did NOT use "start_listener" for the event listener! You said: c.addEventListener('mousemove', function(evt) { mousePos = getPosition(ctm, evt); message = 'Mouse position: ' + mousePos.x + ',' + mousePos.y; }, false); and NOT: c.addEventListener('mousemove', start_listener); If you want to add a listener which should be removable, you must do that in this way: function myListener(evt) { ... } c.addEventListener('mousemove', myListener); ... c.removeEventListener('mousemove', myListener); Also see: -- Arno Welzel https://arnowelzel.de