123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|373|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Web Development -> Cannot read property '0' of undefined

Wed, 25 Jan 2012, 10:44
spinal
For some reason that I don't yet understand, the following code gives me this error -- "Uncaught TypeError: Cannot read property '0' of undefined"



However, when I use that array elsewhere in my code, I don;t get the error.
Can anyone clue me in on what's going wrong?

-=-=-
Check out my excellent homepage!
Wed, 25 Jan 2012, 11:39
9572AD
Do you try to read from items[0] elsewhere?
Wed, 25 Jan 2012, 11:54
spinal


works fine elsewhere in the program.

-=-=-
Check out my excellent homepage!
Wed, 25 Jan 2012, 12:15
9572AD
Will a test for items[0]==1 throw up a flag if items[0] is undefined? It may just say, nope, not equal to one and continue.

-=-=-
All the raw, animal magnetism of a rutabaga.
Wed, 25 Jan 2012, 14:39
spinal
Here's a crazy solution, if I put
into a different file (levels.js) everything works fine. That makes no sense to me at all.

-=-=-
Check out my excellent homepage!
Wed, 25 Jan 2012, 15:16
shroom_monk
I can't see anything obviously out of place... I guess you may have already tried this, but what happens if you replace the parameters of strokeText and fillText with (hardcoded) the values that might be stored in your array? Just to double-check the exact location of the problem. Could the '0' not be one of the values stored in the array rather than the subscript of the array cell?

-=-=-
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Wed, 25 Jan 2012, 18:27
CodersRule
What if you replace "var items =" with "window.items ="? Does it work then? Perhaps you can create a proper global variable that way.