Sorting 10 movie clips

I have on a scaleble SWF, 10 movie clips. The´re are numbered from 1 to 10.

And I have a button named “Sort”.
When this button is clicked, the movie cips should move in position according to its number.
So the MC number 1 have to be on _x= 0 and _y= 0, the MC number 2 on _x=100 and _y=0 and so on.

BUT::::

If the SWF is resized and made smaller, the movie clips should go to a second line if there´s no room from them on the _y = 0…

So the second line of MCs would be on _x=0 and _y=250 and so on.

How this can be made?
Hope I have been clear enough :beam: