The code below links to an xml file (currentData). There are three candidates running in an election. The counties (aButtons array) on a state map need to change colors depending on which candidate has the highest percentage of the vote. I’ve simplified the code so that the counties on the map will only reflect the color assigned to the first candidate if his percentage of the vote is higher than the other two candidates. The code below almost works. Several counties change to the correct color, but there are a couple of counties where the first candidate has a higher percentage and yet they do not change colors. I’ve tested this thing over and over until I am pretty sure that the conditional statement is the problem.
colorChange(currentData);
function colorChange(currentData) {
var xmlColorChange:XML = new XML();
xmlColorChange.ignoreWhite = true;
xmlColorChange.load(currentData);
xmlColorChange.onLoad = function() {
for (var k:Number = 0; k<xmlColorChange.firstChild.childNodes.length; k++) {
candidateOneMapColor = (xmlColorChange.firstChild.childNodes[k].attributes.percent0);
candidateTwoMapColor = (xmlColorChange.firstChild.childNodes[k].attributes.percent1);
candidateThreeColor = (xmlColorChange.firstChild.childNodes[k].attributes.percent2);
var mapcolor = new Color(aButtonsColor[k]);
if (candidateOneMapColor>candidateTwoMapColor && candidateOneMapColor>candidateThreeMapColor) {
mapcolor.setRGB(demOnecolor);
}
}
};
}