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


Groups > comp.lang.javascript > #38845

Re: Stop the mouse listener

Newsgroups comp.lang.javascript
Date 2020-09-24 09:09 -0700
References (2 earlier) <f9510aee-24b1-4fc7-8fee-7c6e6e0fcc4bo@googlegroups.com> <ht32qcFf7auU1@mid.individual.net> <e086c107-6fb0-44ba-9c4f-09cfe4db1575o@googlegroups.com> <74460df3-6973-4fe2-bb7c-2610c22f2228o@googlegroups.com> <8ed3c65d-8275-42cd-8ce5-e55330f05264o@googlegroups.com>
Message-ID <eeea2690-6b0f-42dd-beba-82c320bfdfa2o@googlegroups.com> (permalink)
Subject Re: Stop the mouse listener
From Jonas Thörnvall <jonas.thornvall@gmail.com>

Show all headers | View raw


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>

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