Need some help with this code pls

Hi,

I m trying to build a dynamic thumbnail loader. I managed to load the thumbnails and distribute them into rows according to the stage width. Though, the on press function is not activated since the thumbnails are not really loaded till that function is called. I tried adding several preloading methods but [Type Function] is outputted.

Can anyone help pls?

Thanks

//Intial Values
xCoordinate = 20;
yCoordinate = 20;
x_coordinate = xCoordinate;
y_coordinate = yCoordinate;
thumbSpace = 5;
image_folder = “thumbs/”;
filetype = “.jpg”;
totalImages = 12;
thumbHeight = 50;
thumbWidth = 50;

//Actual Stage area
stageWidth = Stage.width - (x_coordinate2);
stageHeight = Stage.height - (y_coordinate
2);
//How many thumbs fit in a row
fittedThumbs = Math.floor(stageWidth/(thumbWidth + thumbSpace));

//Create MovieClips and load thumbs in them
for(i=1;i<=totalImages;i++){
createEmptyMovieClip(“thumb” add i, i);
theThumb = eval(“thumb” add i);

//Listener
//thumbLoader = new MovieClipLoader();
//thumbListener = new Object();
//thumbListener.onLoadComplete = function(theThumb){
// trace(“Loaded”);
//}

theThumb._x = x_coordinate;
theThumb._y = y_coordinate;
theThumb.loadMovie(image_folder + i + filetype);

//On events
theThumb.onLoad = function(){
trace(“pressed”);
}

//Add a space between a thumb and another
x_coordinate += thumbWidth + thumbSpace;

//Create rows
if(totalImages>=fittedThumbs){
if(i==fittedThumbs){
x_coordinate = xCoordinate;
y_coordinate += thumbHeight + thumbSpace;
}
if(i==fittedThumbs2){
x_coordinate = xCoordinate;
y_coordinate += thumbHeight + thumbSpace;
}
if(i==fittedThumbs
3){
x_coordinate = xCoordinate;
y_coordinate += thumbHeight + thumbSpace;
}
}
trace(thumb1.getBytesLoaded);
}

trace(stageHeight);