sortOn Messing Up my Arrays

Hi there,

I’m using the .sortOn() function in AS3.0 to sort an array with multiple elements.

First, I push the values to the array, like this:

standingsQSR.push({pts: ptsVal, nam: namTemp, goal: target}); //push values to array

Then I sort it, like this:

standingsQSR.sortOn(["pts", "nam", "goal"], Array.DESCENDING); //sort array

The program has a number of “loops” it goes through. So, I push data to this array (which is global) a first time, sort it, and then later I clear the array with the .shift() function in conjunction with a for loop. I then push new data to the array with the same line of code mentioned above.

But what’s happening is this: on the first round, everything works great, and this is what my output looks like:

standingsQSR[0].nam = West
standingsQSR[1].nam = Central
standingsQSR[2].nam = East
//sortOn Function appears here in code.
standingsQSR[0].nam = East
standingsQSR[1].nam = Central
standingsQSR[2].nam = West

^
This is correct.

Then on the second round:

standingsQSR[0].nam = BC
standingsQSR[1].nam = Southern Alberta
standingsQSR[2].nam = Northern Alberta & Prairies      [ correct data ]
//exact same sortOn function here
standingsQSR[0].nam = BC
standingsQSR[1].nam = Northern Alberta & Prairies
standingsQSR[2].nam = Northern Alberta & Prairies    [ ah!! ]

What the heck?

Before I cleared the array with for loop and .shift(), it would say “Northern Alberta & Prairies” in ALL array slots. Since I started using the .shift() function I managed to get BC to remain, but it’s still clearing my southern alberta entry.

Any ideas as to what’s happening? Many thanks!!