Strange Array Problem + maxValue Tutorial

Hi everyone,
I’ve run into a weird problem with regards to my maxValue function (http://www.kirupa.com/developer/actionscript/array_max_min.htm) and an array.

In one scenario, I am using an array that was populated with data from an XML file. I am going to pass that data to my maxValue function. Prior to passing the array to the maxValue function, I trace my array to make sure that all of the values have been loaded. When I pass that array to the following maxValue function:

maxValue = function (array) {
mx = array[0];
for (z=0; z<total; z++) {
if (array[z]>mx) {
mx = array[z];
}
trace(z+" "+mx+" "+array[z]);
}
return mx;
};

I get the following output:

0 43 43
1 54 54
2 99 99
3 99 234
4 99 223
5 99 432
6 99 405
7 99 151

The first number is the index number, the second number is the value of the mx (maximum) number, and the third number is the current number in our array. Obviously, this isn’t correct for the value for maximum does not change beyond 99. For example, 99 is not greater than 234 as shown by the output.

What is strange, though, is if I pass the same data from an array I declare with values manually filled in as opposed to being filled in from an XML file, I get the correct output:

0 43 43
1 54 54
2 99 99
3 234 234
4 234 223
5 432 432
6 432 405
7 432 151

What I don’t understand is that both arrays contain the same value, and they both are completely filled prior to the call to maxValue, yet the array filled with data from the XML file is giving me erronous results.

Does anybody have any idea as to why that is occuring? I can post an FLA + XML file if you all want.

Thanks!
Kirupa :slight_smile: