Photo gallery using grid

Hi!.. I am using the following code to create a photo gallery with thumbnails… however, I need a grid system cause all the photos do not fit in a horizontal or vertical line. I have searched the forum but since I don’t have much clue of actionscript I don’t know how to fit the script here… can anyone help me? Thanks.

myPhoto = new XML();
myPhoto.ignoreWhite = true;
myPhoto.onLoad = function(success) {
//portfolioTag = this.firstChild;
numimages = this.firstChild.childNodes.length;
spacing = 70;
for (i=0; i<numimages; i++) {
this.picHolder = this.firstChild.childNodes*;
this.thumbHolder = thumbnails.createEmptyMovieClip(“thumbnail”+i, i);
this.thumbHolder._y = i*spacing;
this.thumbLoader = this.thumbHolder.createEmptyMovieClip(“thumbnail_image”, 0);
this.thumbLoader.loadMovie(this.picHolder.attributes.thmb);
this.thumbHolder.title = this.picHolder.attributes.title;
this.thumbHolder.main = this.picHolder.attributes.main;
this.thumbHolder.onRelease = function() {
loader.loadMovie(this.main);
title_txt.text = this.title;
};
}
};
myPhoto.load(“xmlphoto.xml”);