This gives an error in IE function x() { length = getPathLength(); } function getPathLength() { //return the length of the path var num = polyPoints.length; if(num > 1){ var ret = 0; for(var i = 0; i < (num-1); ++i){ ret += polyPoints[i].distanceFrom(polyPoints[i+1]); } ret = ret.toFixed(3)/1000; return ret; } return NaN; } Code (markup): I know length = getPathLength(); gives me the error in IE, because if i deleted that part it doesn't show an error. Any tips??
no, that's properly not it. polyPoints is a global var. Like i said if i delete length = getPathLength(); Code (markup): from the function i get no errors Any other thoughts?
Can you fill in the rest of the script including the (assuming html) that calls it. At a guess I'd say that the reason you don't get an error when you remove that line of code is because the function is only called from that line of code. Generally speaking firefox is much more forgiving that IE.
Try i++ instead of ++i I believe in the very first iteration of your loop i will be 1 not 0, so that in your last loop i = num (because you are pre-incrementing i before entering loop. you evaluate i < (num - 1) then immediatly increment i. i++ says do the loop then increment me. ++i says increment me then to loop Anyway, this code looks familiar. Aren't you also going to want an if statement in the loop like if( i == (num - 1)) ret += polyPoints.distanceFrom(polyPoints[0]); else ret += polyPoints.distanceFrom(polyPoints[i+1]); that will compute the total boundry length if your points are stored in order (say...clockwise direction)