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


Groups > comp.lang.javascript > #38829 > unrolled thread

Stop the mouse listener

Started byJonas Thörnvall <jonas.thornvall@gmail.com>
First post2020-09-23 00:16 -0700
Last post2020-09-26 11:05 -0700
Articles 20 on this page of 37 — 8 participants

Back to article view | Back to comp.lang.javascript


Contents

  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

Page 1 of 2  [1] 2  Next page →


#38829 — Stop the mouse listener

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-09-23 00:16 -0700
SubjectStop the mouse listener
Message-ID<a9143f95-5e0b-404f-b734-776ce6a3feb9o@googlegroups.com>
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) {
        mouseUp = getPosition(ctm, evt);
        message = 'Mouse up: ' + mouseUp.x + ',' + mouseUp.y;
    }, false);
    c.addEventListener("mousedown", function(evt) {
        mouseDown = getPosition(ctm, evt);
        message = 'Mouse down: ' + mouseDown.x + ',' + mouseDown.y;
        mousedown_logic();
    }, false);
    c.addEventListener('mousemove', function(evt) {
       mousePos = getPosition(ctm, evt);
       message = 'Mouse position: ' + mousePos.x + ',' + mousePos.y;
    }, false);
}

// Get X, Y cordinates mouse position
function getPosition(ctm, evt) {
    var rect = c.getBoundingClientRect();
    return {
        x: evt.clientX - rect.left,
        y: evt.clientY - rect.top
    };
	
}

[toc] | [next] | [standalone]


#38830

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-09-23 00:31 -0700
Message-ID<d6e82db2-9337-4609-a55a-e0819014f240o@googlegroups.com>
In reply to#38829
Den onsdag 23 september 2020 kl. 09:16:55 UTC+2 skrev Jonas Thörnvall:
> 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) {
>         mouseUp = getPosition(ctm, evt);
>         message = 'Mouse up: ' + mouseUp.x + ',' + mouseUp.y;
>     }, false);
>     c.addEventListener("mousedown", function(evt) {
>         mouseDown = getPosition(ctm, evt);
>         message = 'Mouse down: ' + mouseDown.x + ',' + mouseDown.y;
>         mousedown_logic();
>     }, false);
>     c.addEventListener('mousemove', function(evt) {
>        mousePos = getPosition(ctm, evt);
>        message = 'Mouse position: ' + mousePos.x + ',' + mousePos.y;
>     }, false);
> }
> 
> // Get X, Y cordinates mouse position
> function getPosition(ctm, evt) {
>     var rect = c.getBoundingClientRect();
>     return {
>         x: evt.clientX - rect.left,
>         y: evt.clientY - rect.top
>     };
> 	
> }

I will add a button that basicly strips array from unwanted/superfluos moves so you can jump right in anywhere.

I can scroll thru back and forth now but it introduce some bug, and i do not take care off pawn promotion and castling.

But first i must fix so i can lockdown board.
https://jonasth.github.io/chess/chess.html

[toc] | [prev] | [next] | [standalone]


#38832

FromJJ <jj4public@gmail.com>
Date2020-09-23 18:49 +0700
Message-ID<8zsym7odbn9r.1b62v3cn8pck0$.dlg@40tude.net>
In reply to#38829
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.

[toc] | [prev] | [next] | [standalone]


#38833

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-09-23 05:42 -0700
Message-ID<f9510aee-24b1-4fc7-8fee-7c6e6e0fcc4bo@googlegroups.com>
In reply to#38832
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...?

I do not get what you mean not even used as event handler, it work perfect to move the pieces.If i never call the function then they will not work/start.

JT 

https://jonasth.github.io/chess/chess.html

[toc] | [prev] | [next] | [standalone]


#38834

FromSilvio <silvio@internet.com>
Date2020-09-23 20:25 +0200
Message-ID<5f6b9327$0$2808$e4fe514c@newszilla.xs4all.nl>
In reply to#38833
On 9/23/20 2:42 PM, Jonas Thörnvall wrote:
> 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...?
> 
> I do not get what you mean not even used as event handler, it work perfect to move the pieces.If i never call the function then they will not work/start.
> 
> JT
> 
> https://jonasth.github.io/chess/chess.html
> 

JJ is right. The parameter to removeEventListener needs to be the exact 
same value as was used for addEventListener. And it is not since you did 
not use start_listener as the listener. As usually your code is messy 
and lacks structure.
Create a function value that holds the listener and pass that to 
addEventListener / removeEventListener.

[toc] | [prev] | [next] | [standalone]


#38835

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-09-23 15:22 -0700
Message-ID<b97cbc88-6425-4da2-9f9d-14cc262e7987o@googlegroups.com>
In reply to#38834
Den onsdag 23 september 2020 kl. 20:26:32 UTC+2 skrev Silvio:
> On 9/23/20 2:42 PM, Jonas Thörnvall wrote:
> > 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...?
> > 
> > I do not get what you mean not even used as event handler, it work perfect to move the pieces.If i never call the function then they will not work/start.
> > 
> > JT
> > 
> > https://jonasth.github.io/chess/chess.html
> > 
> 
> JJ is right. The parameter to removeEventListener needs to be the exact 
> same value as was used for addEventListener. And it is not since you did 
> not use start_listener as the listener. As usually your code is messy 
> and lacks structure.
> Create a function value that holds the listener and pass that to 
> addEventListener / removeEventListener.

I am not even understand what you mean, for certain the listeners start when the function start_listener called, other wise i would not be ablle pickout object from array.

Right now i only use mousedown, **but why you say i do not start the listener***, i can agree some little anal fart created the monkey syntax of javascript eventhandlers but why would it not work the way i do it. I simply remove the codepiece invoked in startListener which happen to be "mousedown". How the idiots managed todo a syntax of an event handler that is basicly incomprehensible from both reading, implementing and understanding point is beyone me...


c.addEventListener("mousedown", function(evt) {
        mouseDown = getPosition(ctm, evt);
        message = 'Mouse down: ' + mouseDown.x + ',' + mouseDown.y;
        mousedown_logic();
}, false);

[toc] | [prev] | [next] | [standalone]


#38836

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-09-23 15:31 -0700
Message-ID<ca20d4ad-9748-4836-a8c0-bfe1f398ff51o@googlegroups.com>
In reply to#38834
Den onsdag 23 september 2020 kl. 20:26:32 UTC+2 skrev Silvio:
> On 9/23/20 2:42 PM, Jonas Thörnvall wrote:
> > 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...?
> > 
> > I do not get what you mean not even used as event handler, it work perfect to move the pieces.If i never call the function then they will not work/start.
> > 
> > JT
> > 
> > https://jonasth.github.io/chess/chess.html
> > 
> 
> JJ is right. The parameter to removeEventListener needs to be the exact 
> same value as was used for addEventListener. And it is not since you did 
> not use start_listener as the listener. As usually your code is messy 
> and lacks structure.
> Create a function value that holds the listener and pass that to 
> addEventListener / removeEventListener.

I am quite satisfied with just copy the oneliner that will show how to stop the mousedown eventhandler that evidently running. I am not even curious to know how the monkeys was thinking implementing it, because it so evidently convoluted anal trash thoughts.

I hope you do not mean that the event handler code can not be reached when started from inside a function because then someone really had the asshat on constructing the syntax for the eventhandler.

[toc] | [prev] | [next] | [standalone]


#38837

FromArno Welzel <usenet@arnowelzel.de>
Date2020-09-24 10:14 +0200
Message-ID<ht32qcFf7auU1@mid.individual.net>
In reply to#38833
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

[toc] | [prev] | [next] | [standalone]


#38838

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-09-24 02:38 -0700
Message-ID<142df542-54c0-47fe-8533-a849ad472730o@googlegroups.com>
In reply to#38837
Den torsdag 24 september 2020 kl. 10:14:13 UTC+2 skrev Arno Welzel:
> 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

Did as you said and let the eventlistener flappin in the breeze.
But it never starts.

c.addEventListener("mousedown", myListener);

function myListener(){
     mouseDown = getPosition(ctm, evt);
     message = 'Mouse down: ' + mouseDown.x + ',' + mouseDown.y;
     mousedown_logic();
}

[toc] | [prev] | [next] | [standalone]


#38840

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-09-24 02:45 -0700
Message-ID<e65ff7e9-815d-4741-a133-dae4496437cao@googlegroups.com>
In reply to#38838
Den torsdag 24 september 2020 kl. 11:38:38 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 24 september 2020 kl. 10:14:13 UTC+2 skrev Arno Welzel:
> > 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
> 
> Did as you said and let the eventlistener flappin in the breeze.
> But it never starts.
> 
> c.addEventListener("mousedown", myListener);
> 
> function myListener(){
>      mouseDown = getPosition(ctm, evt);
>      message = 'Mouse down: ' + mouseDown.x + ',' + mouseDown.y;
>      mousedown_logic();
> }

Actually i now see it say c is not defined but it certainly is elsewhere "and using the function".

[toc] | [prev] | [next] | [standalone]


#38851

FromArno Welzel <usenet@arnowelzel.de>
Date2020-09-24 19:43 +0200
Message-ID<ht445hFn124U1@mid.individual.net>
In reply to#38838
Jonas Thörnvall:

> Den torsdag 24 september 2020 kl. 10:14:13 UTC+2 skrev Arno Welzel:
[...]
>> 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);

[...]
> Did as you said and let the eventlistener flappin in the breeze.
> But it never starts.
> 
> c.addEventListener("mousedown", myListener);
> 
> function myListener(){
>      mouseDown = getPosition(ctm, evt);
>      message = 'Mouse down: ' + mouseDown.x + ',' + mouseDown.y;
>      mousedown_logic();
> }

See the example here:

<https://jsfiddle.net/2sd9eocq/>



-- 
Arno Welzel
https://arnowelzel.de

[toc] | [prev] | [next] | [standalone]


#38839

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-09-24 02:42 -0700
Message-ID<a62207a2-64c9-4601-9836-5a27c5a913f7o@googlegroups.com>
In reply to#38837
Den torsdag 24 september 2020 kl. 10:14:13 UTC+2 skrev Arno Welzel:
> 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

Thanks for the concrete anyway, the other willy nillys just flapping in the wind as usual.

[toc] | [prev] | [next] | [standalone]


#38841

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-09-24 02:52 -0700
Message-ID<e086c107-6fb0-44ba-9c4f-09cfe4db1575o@googlegroups.com>
In reply to#38837
Den torsdag 24 september 2020 kl. 10:14:13 UTC+2 skrev Arno Welzel:
> 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

Could i have 
c = document.getElementById("myCanvas");
ctm = c.getContext("2d");

in a function or should they also just flap in the breeze, and must that breeze be in the same file as mouselistener?

Because evidently the file with event mousecode do not reach "c" flapping in the wind.

[toc] | [prev] | [next] | [standalone]


#38842

Fromluserdroog <luser.droog@gmail.com>
Date2020-09-24 08:32 -0700
Message-ID<74460df3-6973-4fe2-bb7c-2610c22f2228o@googlegroups.com>
In reply to#38841
On Thursday, September 24, 2020 at 4:52:24 AM UTC-5, Jonas Thörnvall wrote:
> 
> Could i have 
> c = document.getElementById("myCanvas");
> ctm = c.getContext("2d");
> 
> in a function or should they also just flap in the breeze, and must that breeze be in the same file as mouselistener?
> 
> Because evidently the file with event mousecode do not reach "c" flapping in the wind.

Sure, it can be in a function. Since you're not using `var` or `let`
or `const`, then c and ctm will have global scope. So as soon as the
function is called, these variables should be defined.

[toc] | [prev] | [next] | [standalone]


#38843

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-09-24 08:59 -0700
Message-ID<8ed3c65d-8275-42cd-8ce5-e55330f05264o@googlegroups.com>
In reply to#38842
Den torsdag 24 september 2020 kl. 17:32:29 UTC+2 skrev luserdroog:
> On Thursday, September 24, 2020 at 4:52:24 AM UTC-5, Jonas Thörnvall wrote:
> > 
> > Could i have 
> > c = document.getElementById("myCanvas");
> > ctm = c.getContext("2d");
> > 
> > in a function or should they also just flap in the breeze, and must that breeze be in the same file as mouselistener?
> > 
> > Because evidently the file with event mousecode do not reach "c" flapping in the wind.
> 
> Sure, it can be in a function. Since you're not using `var` or `let`
> or `const`, then c and ctm will have global scope. So as soon as the
> function is called, these variables should be defined.

Well it seem they are not, i get message not defined could it be they rest in another file? I am pretty sure i got the file order so that c and ctm load before eventhandler for mouse, i did put them in the first SRC file with the function called directly from HTML at load. 

But i get c is not defined, and it is c i should refer to the document canvas object, ctm is just properties/context of it?

[toc] | [prev] | [next] | [standalone]


#38844

Fromluserdroog <luser.droog@gmail.com>
Date2020-09-24 09:08 -0700
Message-ID<22611062-61d7-4fe8-b898-8400c53e5502o@googlegroups.com>
In reply to#38843
On Thursday, September 24, 2020 at 11:00:06 AM UTC-5, Jonas Thörnvall wrote:
> Den torsdag 24 september 2020 kl. 17:32:29 UTC+2 skrev luserdroog:
> > On Thursday, September 24, 2020 at 4:52:24 AM UTC-5, Jonas Thörnvall wrote:
> > > 
> > > Could i have 
> > > c = document.getElementById("myCanvas");
> > > ctm = c.getContext("2d");
> > > 
> > > in a function or should they also just flap in the breeze, and must that breeze be in the same file as mouselistener?
> > > 
> > > Because evidently the file with event mousecode do not reach "c" flapping in the wind.
> > 
> > Sure, it can be in a function. Since you're not using `var` or `let`
> > or `const`, then c and ctm will have global scope. So as soon as the
> > function is called, these variables should be defined.
> 
> Well it seem they are not, i get message not defined could it be they rest in another file? I am pretty sure i got the file order so that c and ctm load before eventhandler for mouse, i did put them in the first SRC file with the function called directly from HTML at load. 
> 
> But i get c is not defined, and it is c i should refer to the document canvas object, ctm is just properties/context of it?

Put a

  console.log('defined');

in the function to be absolutely sure it is being run when you
think it is. If it's deferred somehow, it might not have run
yet at the point you're expecting.

[toc] | [prev] | [next] | [standalone]


#38846

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-09-24 09:25 -0700
Message-ID<5a2007b6-cd1d-415c-bc48-f4e790b74abeo@googlegroups.com>
In reply to#38844
Den torsdag 24 september 2020 kl. 18:08:37 UTC+2 skrev luserdroog:
> On Thursday, September 24, 2020 at 11:00:06 AM UTC-5, Jonas Thörnvall wrote:
> > Den torsdag 24 september 2020 kl. 17:32:29 UTC+2 skrev luserdroog:
> > > On Thursday, September 24, 2020 at 4:52:24 AM UTC-5, Jonas Thörnvall wrote:
> > > > 
> > > > Could i have 
> > > > c = document.getElementById("myCanvas");
> > > > ctm = c.getContext("2d");
> > > > 
> > > > in a function or should they also just flap in the breeze, and must that breeze be in the same file as mouselistener?
> > > > 
> > > > Because evidently the file with event mousecode do not reach "c" flapping in the wind.
> > > 
> > > Sure, it can be in a function. Since you're not using `var` or `let`
> > > or `const`, then c and ctm will have global scope. So as soon as the
> > > function is called, these variables should be defined.
> > 
> > Well it seem they are not, i get message not defined could it be they rest in another file? I am pretty sure i got the file order so that c and ctm load before eventhandler for mouse, i did put them in the first SRC file with the function called directly from HTML at load. 
> > 
> > But i get c is not defined, and it is c i should refer to the document canvas object, ctm is just properties/context of it?
> 
> Put a
> 
>   console.log('defined');
> 
> in the function to be absolutely sure it is being run when you
> think it is. If it's deferred somehow, it might not have run
> yet at the point you're expecting.

Well now i put it in the canvas declaration in the HTML <script>
I put it in the breeze of gameengine.js and i put it in function in gameengine.js all same conclusion c is not defined.

This is what c holds from console.log i moved the canvas declaration back to script in html file.
<canvas id="myCanvas" width="1910" height="770"></canvas>

[toc] | [prev] | [next] | [standalone]


#38845

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-09-24 09:09 -0700
Message-ID<eeea2690-6b0f-42dd-beba-82c320bfdfa2o@googlegroups.com>
In reply to#38843
Den torsdag 24 september 2020 kl. 18:00:06 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 24 september 2020 kl. 17:32:29 UTC+2 skrev luserdroog:
> > On Thursday, September 24, 2020 at 4:52:24 AM UTC-5, Jonas Thörnvall wrote:
> > > 
> > > Could i have 
> > > c = document.getElementById("myCanvas");
> > > ctm = c.getContext("2d");
> > > 
> > > in a function or should they also just flap in the breeze, and must that breeze be in the same file as mouselistener?
> > > 
> > > Because evidently the file with event mousecode do not reach "c" flapping in the wind.
> > 
> > Sure, it can be in a function. Since you're not using `var` or `let`
> > or `const`, then c and ctm will have global scope. So as soon as the
> > function is called, these variables should be defined.
> 
> Well it seem they are not, i get message not defined could it be they rest in another file? I am pretty sure i got the file order so that c and ctm load before eventhandler for mouse, i did put them in the first SRC file with the function called directly from HTML at load. 
> 
> But i get c is not defined, and it is c i should refer to the document canvas object, ctm is just properties/context of it?

This is the errorcode i get.
Uncaught ReferenceError: c is not defined
    at mouse.js:29


//These are in game engine does not matter inside early called function, or just flapping around in file. 
c = document.getElementById("myCanvas");
ctm = c.getContext("2d");



//This code is in mouse.js
c.addEventListener("mousedown", myListener);

function myListener(){
	 mouseDown = getPosition(ctm, evt);
     message = 'Mouse down: ' + mouseDown.x + ',' + mouseDown.y;
     mousedown_logic();
}

//This is my script sources in my HTML file, as you can see gameengine.js->mouse.js

<html>
<head>
<script src="gameengine.js"></script>
<script src="initchess.js"></script>
<script src="mouse.js"></script>
<script src="draw.js"></script>
<script src="boardSetup.js"></script>
<script src="boardanalyse.js"></script>
<script src="bishop.js"></script>
<script src="rock.js"></script>
<script src="knight.js"></script>
<script src="queen.js"></script>
<script src="king.js"></script>
<script src="pawn.js"></script>
<script src="castling.js"></script>
<script src="checked.js"></script>
<script src="replay.js"></script>
</head>

[toc] | [prev] | [next] | [standalone]


#38847

Fromluserdroog <luser.droog@gmail.com>
Date2020-09-24 09:53 -0700
Message-ID<8547b038-7a8d-419f-b4a8-91942b5a5891o@googlegroups.com>
In reply to#38845
On Thursday, September 24, 2020 at 11:09:49 AM UTC-5, Jonas Thörnvall wrote:
> Den torsdag 24 september 2020 kl. 18:00:06 UTC+2 skrev Jonas Thörnvall:
> > Den torsdag 24 september 2020 kl. 17:32:29 UTC+2 skrev luserdroog:
> > > On Thursday, September 24, 2020 at 4:52:24 AM UTC-5, Jonas Thörnvall wrote:
> > > > 
> > > > Could i have 
> > > > c = document.getElementById("myCanvas");
> > > > ctm = c.getContext("2d");
> > > > 
> > > > in a function or should they also just flap in the breeze, and must that breeze be in the same file as mouselistener?
> > > > 
> > > > Because evidently the file with event mousecode do not reach "c" flapping in the wind.
> > > 
> > > Sure, it can be in a function. Since you're not using `var` or `let`
> > > or `const`, then c and ctm will have global scope. So as soon as the
> > > function is called, these variables should be defined.
> > 
> > Well it seem they are not, i get message not defined could it be they rest in another file? I am pretty sure i got the file order so that c and ctm load before eventhandler for mouse, i did put them in the first SRC file with the function called directly from HTML at load. 
> > 
> > But i get c is not defined, and it is c i should refer to the document canvas object, ctm is just properties/context of it?
> 
> This is the errorcode i get.
> Uncaught ReferenceError: c is not defined
>     at mouse.js:29
> 
> 
> //These are in game engine does not matter inside early called function, or just flapping around in file. 
> c = document.getElementById("myCanvas");
> ctm = c.getContext("2d");
> 

I tried peeking through your github files, but I couldn't find
these lines in any of the files I looked at.

If it's at the top level (ie. flappin in the breeze) then it 
must be in a file that's loaded earlier than the one where
you use it (or earlier than any calls to functions that might
use it. Could it be that you're editing multiple files at once
and maybe occasionally forgetting to save one before testing?

BTW, 'c' probably isn't the greatest name to use for
a global variable.

[toc] | [prev] | [next] | [standalone]


#38848

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-09-24 10:00 -0700
Message-ID<75caf153-67ea-4572-a707-1784128c97f7o@googlegroups.com>
In reply to#38847
Den torsdag 24 september 2020 kl. 18:53:46 UTC+2 skrev luserdroog:
> On Thursday, September 24, 2020 at 11:09:49 AM UTC-5, Jonas Thörnvall wrote:
> > Den torsdag 24 september 2020 kl. 18:00:06 UTC+2 skrev Jonas Thörnvall:
> > > Den torsdag 24 september 2020 kl. 17:32:29 UTC+2 skrev luserdroog:
> > > > On Thursday, September 24, 2020 at 4:52:24 AM UTC-5, Jonas Thörnvall wrote:
> > > > > 
> > > > > Could i have 
> > > > > c = document.getElementById("myCanvas");
> > > > > ctm = c.getContext("2d");
> > > > > 
> > > > > in a function or should they also just flap in the breeze, and must that breeze be in the same file as mouselistener?
> > > > > 
> > > > > Because evidently the file with event mousecode do not reach "c" flapping in the wind.
> > > > 
> > > > Sure, it can be in a function. Since you're not using `var` or `let`
> > > > or `const`, then c and ctm will have global scope. So as soon as the
> > > > function is called, these variables should be defined.
> > > 
> > > Well it seem they are not, i get message not defined could it be they rest in another file? I am pretty sure i got the file order so that c and ctm load before eventhandler for mouse, i did put them in the first SRC file with the function called directly from HTML at load. 
> > > 
> > > But i get c is not defined, and it is c i should refer to the document canvas object, ctm is just properties/context of it?
> > 
> > This is the errorcode i get.
> > Uncaught ReferenceError: c is not defined
> >     at mouse.js:29
> > 
> > 
> > //These are in game engine does not matter inside early called function, or just flapping around in file. 
> > c = document.getElementById("myCanvas");
> > ctm = c.getContext("2d");
> > 
> 
> I tried peeking through your github files, but I couldn't find
> these lines in any of the files I looked at.
> 
> If it's at the top level (ie. flappin in the breeze) then it 
> must be in a file that's loaded earlier than the one where
> you use it (or earlier than any calls to functions that might
> use it. Could it be that you're editing multiple files at once
> and maybe occasionally forgetting to save one before testing?
> 
> BTW, 'c' probably isn't the greatest name to use for
> a global variable.

Honestly i can't be bothered with syntax that do not make sense. Maybe it was a bad idea to drop the listener anyway i just set a boolean for the mouse down call.

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.javascript


csiph-web