Announcement

Do not use the forums to submit bug reports, feature requests or patches, submit a New Ticket instead.

#1 2007-01-18 11:56:35

evilc
Xinha Community Member
Registered: 2005-12-18
Posts: 19

wierd 'has no properties' bug for variable unlrelated to xinha

If I include the xinhacore.js script, I get an error message moaning about one of the variables in my project in the javascript debug window, which stops execution.

The error is:

tmpIconArray[i].start has no properties.

(tmpIconArray has nothing to do with xinha, its a var in my app that holds arrays of icons for a map)

So I went into my code, commented out all exmaples of tmpIconArray, and all runs fine, with the xinha window displayed. However, functions of my program don't work becuse I had to comment out some lines.

If I now put one line back into my code featuring the var tmpIconArray:

alert(tmpIconArray[i]['start']['image']);

Once I do this, the ALERT executes OK, it shows me the (valid) contents of tmpIconArray, but I still get the 'has no properties' error in the debug window and execution stops.

How can the error be true when the only line containing tmpIconArray correctly outputs it's contents?

Why should xinha affect a variable that has nothing to do with it??

The only thing I can think of is it is something to do with the way the array is assembled.
It comes from PHP, with PHP building the array by constructing echo statesments to echo out the JS.
However, all worked fine before I tried to integrate xinha.

I tried various versions of xinha - all have the same issue

Posting example code will be difficult, it's my app that it is conflicting with, and that requires PHP, MYSQL, phpBB and Google Maps. If I get no answers, I suppose I will try and craft a basic php and JS page that has the same problem.

Please anyone, any ideas?

Last edited by evilc (2007-01-18 12:00:00)

Offline

#2 2007-01-18 12:10:35

evilc
Xinha Community Member
Registered: 2005-12-18
Posts: 19

Re: wierd 'has no properties' bug for variable unlrelated to xinha

Also worth noting is that there is another var in my app called iconArray which is built in almost exactly the same way, etc as tmpIconArray, but does not suffer from this issue. I am so stumped sad

Offline

#3 2007-01-18 14:47:33

evilc
Xinha Community Member
Registered: 2005-12-18
Posts: 19

Re: wierd 'has no properties' bug for variable unlrelated to xinha

I have replicated this issue (Not calling it a bug - yet!, I spose it could be my fault) and put up a page to demonstrate it:

http://www.evilc.com/xb/xb.php

Full source code @ http://www.evilc.com/xb/

Offline

#4 2007-01-18 17:04:24

ray
Xinha Administrator
From: Germany
Registered: 2005-03-23
Posts: 521
Website

Re: wierd 'has no properties' bug for variable unlrelated to xinha

In your example XinhaCore.js is not loaded (404)

Offline

#5 2007-01-18 20:44:49

ray
Xinha Administrator
From: Germany
Registered: 2005-03-23
Posts: 521
Website

Re: wierd 'has no properties' bug for variable unlrelated to xinha

Hi, had a look at your code now and found the error
Change

tmpIconArray = new Array();

and the other instances of new Array() to

tmpIconArray = new Object(); // you don't want to use an "Array" here

or easier

tmpIconArray = {}; //this is the same as new Object()
var array = ['value1','value2'];
var associativeArray = {'key1':'value1','key2':'value2'};

(Just to show the difference)

Why it behaved differently with and without Xinha, I don't know smile

Offline

#6 2007-01-18 21:01:02

ray
Xinha Administrator
From: Germany
Registered: 2005-03-23
Posts: 521
Website

Re: wierd 'has no properties' bug for variable unlrelated to xinha

Just googled a bit and found it to be a practice to use Arrays as associative arrays, but as your example shows it's no good practice!

Offline

#7 2007-01-18 21:15:27

evilc
Xinha Community Member
Registered: 2005-12-18
Posts: 19

Re: wierd 'has no properties' bug for variable unlrelated to xinha

Thanks for that.
Xinha wasn't loading cause I forgot to upload it;)

Do all the new array()s in the nested loop need to be new Objects()s or just the one declaring the initial var?

Muchos thanks for helping out here, even though it due to my poor coding not yours wink

For some reason I am having problems with it running locally on this PC, I will try it on my one at work tomorrow.

Offline

#8 2007-01-19 08:01:04

ray
Xinha Administrator
From: Germany
Registered: 2005-03-23
Posts: 521
Website

Re: wierd 'has no properties' bug for variable unlrelated to xinha

Each array you want to index with string keys should be an Object.

Nevermind,  this happens to every php-coder smile

Offline

#9 2007-01-19 08:11:38

evilc
Xinha Community Member
Registered: 2005-12-18
Posts: 19

Re: wierd 'has no properties' bug for variable unlrelated to xinha

Yay! it all works on this other PC, thanks ever so much!

Offline

Board footer

Powered by FluxBB