[FMX] Sorting X values of movie clips

Hi All,

I’ve got five movie clips (called horse1 through horse5) and I want to sort them to find out which has the highest x value. I thought putting them into an array and sorting that would be the best idea but I can’t seem to get even the array to work.

This is the code I have so far;

for (n=1; n<6; n++) {
var hr = “horse”+[n];
myArray=[[“horse”+[n], _level0.hr._x]];
trace (_level0.horse1._x);
trace (myArray);
}

which returns;

487.85
horse1,
487.85
horse2,
487.85
horse3,
487.85
horse4,
487.85
horse5,

I used the ‘hr’ variable because myArray reported an error if I tried
myArray=[[“horse”+[n], _level0.“horse”[n]._x]];

As you can see I do get an x value when I use
trace (_level0.horse1._x);

But I don’t get one if I use
trace (_level0.horse+[n]._x);

Hope this makes some sort of sense. I’m pretty new to this so any help is appreciated.

I’m running Flash MX on a PC.

Thanks,

Roughy

trace this:

[AS]trace (_root[“horse”+n].)_x);[/AS]

thanks norie, but it’s still not happy.

It gives the following output when I run the movie - I put your trace in Line 13.

Scene=Scene 1, Layer=script, Frame=4: Line 13: Expected a field name after ‘.’ operator.
trace (_root[“horse”+n].)_x);

Scene=Scene 1, Layer=script, Frame=4: Line 17: Unexpected ‘}’ encountered
}

opps sorry,


trace (_root["horse"+n]._x);

Thanks norie!

it is working great (now to solve my sorting problem!)

much appreciated,

Roughy

myArray.sort(Array.NUMERIC);

thanks again norie - will work on it