Make these thumbs into a grid?

Hi, I was wondering how I would go about breaking my thumbnails that are dynamically scripted to the stage into a grid right now it just goes straight across the screen and i dont want that :confused:

function createXMLGallery() {
    content_txt.removeTextField();
    var gallery:MovieClip = createEmptyMovieClip("gallery", getNextHighestDepth());
    gallery._x = 315;
    gallery._y = 100;
    var numImages = myxml.firstChild.childNodes[5].childNodes.length;
    var spacing:Number = 110;
    for (var i:Number = 0; i<numImages; i++) {
        this.thumbHolder = myxml.firstChild.childNodes[5].childNodes*.attributes.thumb;
        this.picHolder = myxml.firstChild.childNodes[5].childNodes*.attributes.link;
        this.description = myxml.firstChild.childNodes[5].childNodes*.firstChild.nodeValue;
        this.thumbViewer = gallery.createEmptyMovieClip("thumbnail"+i, i);
        this.thumbViewer._x = i*spacing;
        this.thumbLoader = this.thumbViewer.createEmptyMovieClip("thumbnail_image", getNextHighestDepth());
        this.thumbLoader.loadMovie(this.thumbHolder);
        var numRows:Number = Math.ceil(numImages/3);
        trace(numRows);
    }
}