Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #38837

Re: Stop the mouse listener

Path csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Arno Welzel <usenet@arnowelzel.de>
Newsgroups comp.lang.javascript
Subject Re: Stop the mouse listener
Date Thu, 24 Sep 2020 10:14:04 +0200
Lines 60
Message-ID <ht32qcFf7auU1@mid.individual.net> (permalink)
References <a9143f95-5e0b-404f-b734-776ce6a3feb9o@googlegroups.com> <8zsym7odbn9r.1b62v3cn8pck0$.dlg@40tude.net> <f9510aee-24b1-4fc7-8fee-7c6e6e0fcc4bo@googlegroups.com>
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 <f9510aee-24b1-4fc7-8fee-7c6e6e0fcc4bo@googlegroups.com>
Xref csiph.com comp.lang.javascript:38837

Show key headers only | View raw


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:

<https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener#Matching_event_listeners_for_removal>



-- 
Arno Welzel
https://arnowelzel.de

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Stop the mouse listener Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-23 00:16 -0700
  Re: Stop the mouse listener Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-23 00:31 -0700
  Re: Stop the mouse listener JJ <jj4public@gmail.com> - 2020-09-23 18:49 +0700
    Re: Stop the mouse listener Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-23 05:42 -0700
      Re: Stop the mouse listener Silvio <silvio@internet.com> - 2020-09-23 20:25 +0200
        Re: Stop the mouse listener Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-23 15:22 -0700
        Re: Stop the mouse listener Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-23 15:31 -0700
      Re: Stop the mouse listener Arno Welzel <usenet@arnowelzel.de> - 2020-09-24 10:14 +0200
        Re: Stop the mouse listener Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-24 02:38 -0700
          Re: Stop the mouse listener Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-24 02:45 -0700
          Re: Stop the mouse listener Arno Welzel <usenet@arnowelzel.de> - 2020-09-24 19:43 +0200
        Re: Stop the mouse listener Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-24 02:42 -0700
        Re: Stop the mouse listener Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-24 02:52 -0700
          Re: Stop the mouse listener luserdroog <luser.droog@gmail.com> - 2020-09-24 08:32 -0700
            Re: Stop the mouse listener Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-24 08:59 -0700
              Re: Stop the mouse listener luserdroog <luser.droog@gmail.com> - 2020-09-24 09:08 -0700
                Re: Stop the mouse listener Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-24 09:25 -0700
              Re: Stop the mouse listener Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-24 09:09 -0700
                Re: Stop the mouse listener luserdroog <luser.droog@gmail.com> - 2020-09-24 09:53 -0700
                Re: Stop the mouse listener Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-24 10:00 -0700
                Re: Stop the mouse listener Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-24 10:02 -0700
                Re: Stop the mouse listener Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-24 13:10 -0700
                Re: Stop the mouse listener "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-09-25 13:43 +0200
                Re: Stop the mouse listener Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-25 08:44 -0700
            Re: Stop the mouse listener Julio Di Egidio <julio@diegidio.name> - 2020-09-24 11:28 -0700
              Re: Stop the mouse listener Silvio <silvio@internet.com> - 2020-09-24 23:19 +0200
                Re: Stop the mouse listener Julio Di Egidio <julio@diegidio.name> - 2020-09-24 14:51 -0700
              Re: Stop the mouse listener John G Harris <niam@jghnorth.org.uk.invalid> - 2020-09-25 11:15 +0100
                Re: Stop the mouse listener "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-09-25 13:31 +0200
              Re: Stop the mouse listener luserdroog <luser.droog@gmail.com> - 2020-09-25 11:01 -0700
                Re: Stop the mouse listener Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-09-25 11:06 -0700
                Re: Stop the mouse listener luserdroog <luser.droog@gmail.com> - 2020-09-25 11:15 -0700
                Re: Stop the mouse listener Julio Di Egidio <julio@diegidio.name> - 2020-09-26 04:41 -0700
                Re: Stop the mouse listener Julio Di Egidio <julio@diegidio.name> - 2020-09-26 04:46 -0700
                Re: Stop the mouse listener Julio Di Egidio <julio@diegidio.name> - 2020-09-26 04:33 -0700
                Re: Stop the mouse listener luserdroog <luser.droog@gmail.com> - 2020-09-26 09:32 -0700
                Re: Stop the mouse listener Julio Di Egidio <julio@diegidio.name> - 2020-09-26 11:05 -0700

csiph-web