Tile thumbs from XML

I’m loading some text data from XML (short numbers) and I parse this data in thumbs with text field. Now I want to tile them max 400px in width. After that, they must start to tile in second row at x=0 and after 400px _width they strat with third row…
How to make this?
This is the part of the code:

 
function loadData(success) {
 if (success) {
  someText = new Array();
  nodes = new Array();
  nodes = this.firstChild.childNodes;
  total = nodes.length;
  for (var i = 0; i<total; i++) {
   someText.push(nodes*.attributes.description);
   holder.btn.duplicateMovieClip("btn"+i, i);
   holder["btn"+i].tekst.text = someText*;
   holder["btn"+i]._x = holder["btn"+(i-1)]._x + (holder["btn"+(i-1)].tekst.textWidth)+6;
   if(holder["btn"+i]._x >= 400){
    holder["btn"+i]._y += 20;
   }
  }
 }
 delete nodes;
 delete data_xml;
}