posted
I'm just learning this language, and a little bit frustrated at the moment. I am trying to create an object which stores two arrays, x and y coordinates. Like so:
var polyx = new Array(210,220,220,210); var polyy = new Array(10,10,20,20); aProvince = new jsProvince(polyx, polyy, "city");
Now I try to use it in a function called with 'onclick':
code:
if (isPointInPoly(myProvince.polyx, myProvince.polyy, xpos, ypos)) { // Do some thing }
which is where the problem arises: The polyx array has length zero. Presumably I did not initialise it correctly, but I do not understand what I am doing wrong. Any insights?
Posts: 10645 | Registered: Jul 2004
| IP: Logged |
posted
Um. I might be overlooking something here, but it looks like you're initializing "aProvince" as an instance of jsProvince, but trying to reference the instance "myProvince." Do you initialize "myProvince" anywhere?
Posts: 37449 | Registered: May 1999
| IP: Logged |
posted
Wups. I'm actually initialising a whole array of the things, I tried to simplify the code to show the problem's essential features without getting bogged down in all the details.
quote:Is the initialization in the same script block? And is it there before the function gets called?
Do you have the script at the top of the page or the bottom?
The sequence is:
Define functions by including script files Define image with onclick that calls function Initialise variables.
So it is separate script blocks, but I had the impression that JavaScript variables are global by default?
Posts: 10645 | Registered: Jul 2004
| IP: Logged |