for(var i=0; i<recArray.length;i++){
trace(recArray*.vprod);
}
(I don’t know why this last for sentence cannot be seen correctly in Preview Mode but it’s not an error, it’s working fine…)
And the output is:
8
5
36
250
15
100
!!! ??? Shouldn’t it be ordered in descendent order ?? That’s what I’m trying to do without any result.
I tried to load the values (for each object) as an integer this way:
Here’s your answer… you dont want to use sort on in this case, for sortOn is looking for a fieldname… as in
team=[name: “bobby”, name: “susy”]…
instead, you want to use array.sort, which is a bit of a tricky beast. For adequate results, you need to build a little function that will tell array.sort how you want your items sorted.
function(AtoZ){
return a -b;
}
now, you can do… array.sort(AtoZ), and that will give you the numerical values in the order you want (ascending)… if you want descending…
You’re telling me to create a function so as to tell array.sort how I want my elements sorted.
Suppose I want vprods in descending order:
I should define:
function(ZtoA){ // Shouldn’t this function have a name ???
return b - a;
}
How do I “tell” the sort method to use this function ?
You told me: array.sort(ZtoA) but I don’t understand… how does it know that it should sort on vprod instead of nprod ?
This is not very clear to me… Could you give me an example ?
Glups! I’ve tried the example from MM, and ever theirs doesn’t work well!! About Inigo’s technique, you can use pretty much the same example they give in the Help. But that thing with sortOn is really strange.
Well observed, Inigo! Actually, I asked that question to my Chinese master, and he told me the same thing. So to make things straight, you’d have to enter the number as strings of the same length in the first place:
vprod=“004”;
vprod=“075”;
etc.