Laying out dynamically made movie clips

HI, can anyone tell me how to layout dynamically made empty movie clips.
I’m using a loop to extract photo thumbsnails from an XML file, but i can only get the thumbnails to all run horizontally or all run vertically and i want control their layout so they are limited to 3 thumbnails across.

don’t know if that makes sense, so heres the code i got so far:
this just produces the thumbnails in a vertical line.

var thumb_xspacing = 40;
image_mc._alpha =0;
spacing = 20
gridx = 30;
gridy = 35;
j=0;
function GeneratePortfolio(portfolio_xml){
var portfolioPictures = portfolio_xml.firstChild.childNodes;
for (var i = 0; i < portfolioPictures.length; i++){
var currentPicture = portfolioPictures*;
var currentThumb_mc = menu_mc.createEmptyMovieClip(“thumbnail_mc”+i,i);

    currentThumb_mc.createEmptyMovieClip("thumb_container",0);
    currentThumb_mc.thumb_container.loadMovie(currentPicture.attributes.thumb);
    
    currentThumb_mc._y =  gridx * i;
    currentThumb_mc._x = gridy;
            
    currentThumb_mc.title = currentPicture.attributes.title;
    currentThumb_mc.image = currentPicture.attributes.image;
    currentThumb_mc.width = currentPicture.attributes.width;
    currentThumb_mc.height = currentPicture.attributes.height;
    currentThumb_mc.description = currentPicture.attributes.description;
    //j++
    
    currentThumb_mc.onRollOver = currentThumb_mc.onDragOver = function(){
        info_txt.text = this.title;
        
    }
    currentThumb_mc.onRollOut = currentThumb_mc.onDragOut = function(){
        info_txt.text = "";
    }
    currentThumb_mc.onRelease = function(){    
        main_title.text = this.title;
        description_txt.text = this.description;
        image_mc.photoFader(this.image, this.width, this.height);            
    
        
    }
}

}

MovieClip.prototype.photoFader = function(pic, w, h){
_root.image_mc._alpha = 0;
this.loadMovie(pic);
_root.onEnterFrame = function(){
var t = image_mc.getBytesTotal(), l = image_mc.getBytesLoaded();
if (t != 0 && Math.round(l/t) == 1){
//var w = image_mc._width + spacing, h = image_mc._height + spacing;
_root.expander.resizeMe(w, h);
delete _root.onEnterFrame;
}
}
};

MovieClip.prototype.resizeMe = function(w, h){
var speed = 4;
this.onEnterFrame = function(){
this._width += (w - this._width)/speed;
this._height += (h - this._height)/speed;
if( Math.abs(this._width-w)<1){
this._width = w;
this._height = h;
_root.image_mc._x = this._x - this._width/2 + spacing/2;
_root.image_mc._y = this._y - this._height/2 + spacing/2;
_root.image_mc._alpha = 100;
delete this.onEnterFrame;
}
}
};

// xml object for xml content (defines sources for selections)
var portfolio_xml = new XML();
portfolio_xml.ignoreWhite = true;
portfolio_xml.onLoad = function(success){
if (success) GeneratePortfolio(this);
else main_title.text =“Error loading XML file”; // no success? trace error (wont be seen on web)
}
// load
portfolio_xml.load("…/XML/photos.xml");

stop();