Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Very weird array problem

Status
Not open for further replies.

victorsk

Programmer
Jul 26, 2005
21
CA
Hello,

I have a very strange problem. I've defined an global array 'cursor' like this:
cursor = new Array(5);
and then my function doSomething(evt, current) gets the value of 'current' and is supposed to access 'cursor[current].setAttribute()'
BUT, for some reason, when I try to do that I get:
"Type Error: cursor[current] has no properties" error.

So, then I tried to force 'cursor' array recognize index using conventional for-loop like this:
for (var i = 0; i < 5; i++) {
if (current == i) {
cursor.setAttributeNS(null, "x", cur_x);
cursor.setAttributeNS(null, "y", cur_y);
}
}

Still, I am getting error "cursor has no properties. BUT, if I access 'cursor' like this:
//use 1 here
cursor[1].setAttributeNS(null, "y", cur_y);

everything works fine. Could somebody please tell me what is going on here? It flies against rules of common sense as far I see. Thank you very much.

Victor.
 
Quite interesting question.

What is that method setAttributeNS()?

I have never seen that before.

What kind of things are you storing in the array?

Is cursor a pointer to an object with a method setAttributeNS()?

 
Hi,

Thanks for replying. I am working with SVG and so I am trying to set the properties of an SVG image. I presume 'cursor' is a pointer to an SVG document image:
In my Init(evt) {
cursor[1] = svgDocument.getElementById("image_url0");
}
So, here I am setting it to point(C++ term?) to an image and then set its attributes in my doSomething() method.

Thank you,
Victor.
 
It sounds like you don't have as many cursor objects as you are trying to reference in your loop. Have you tried:

alert(cursor.length);

to see if you're trying to go beyond the end of the array?

And why aren't you using:

for (var i = 0; i < cursor.length; i++)

? Are you declaring the cursor array before or after you try to access the individual elements?

Lee

 
Hi,

Thank you very much for replying. Yes, you were right, I didn't have enough objects and that was the problem, my cursor size was 5 while I assigned values only to cursor[1] - It's been a looooong day :)

Thanks,
Victor.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top