You would use a variable to keep track of the current x
position, and keep adding to it as you loop over the objects:
xml1 = new XML(URLLoader(event.target).data);
var i:Number;
var currentX:Number = 0;
mini = new Array(xml1.obrazek.length());
count = xml1.obrazek.length();
for (i=0; i<count; i++)
{
mini[i] = new Miniaturka(xml1.obrazek[i].attribute("id"),i);
addChild(mini[i]);
mini[i].x = currentX;
currentX += mini[i].width;
}
EDIT:
Since gathering the width of the object is an asynchronous process, you will likely need to wait until each Miniaturka
has received its width from the sizeHandler
method before attempting to create and position the next instance of Miniaturka
.
One way you can do this is to re-dispatch the PARSE_COMPLETE
event from your sizeHandler
and listen for that event in the code where you're instantiating Miniaturka
.
You would have to get rid of the for-loop, and instead position the old instance and create the new instance once the event has been handled.