PDA

View Full Version : [FMX] Sorting X values of movie clips



Roughy
December 15th, 2003, 05:41 PM
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

norie
December 15th, 2003, 06:40 PM
trace this:

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

Roughy
December 15th, 2003, 06:55 PM
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
}

norie
December 15th, 2003, 07:02 PM
opps sorry,


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

Roughy
December 15th, 2003, 07:08 PM
Thanks norie!

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

much appreciated,

Roughy

norie
December 15th, 2003, 07:19 PM
myArray.sort(Array.NUMERIC);

Roughy
December 15th, 2003, 08:25 PM
thanks again norie - will work on it