[FMX] Gallery->centering main image

Hi all.
I didn’t find a solution for my problem.I have set up a gallery (from sources around the net) and i want the main image (the big version of thumnails) to be centerd in an area of 350350 if the image width or height is <350.I have 3 sorts of image size : 350350, <350350, 350<350. The thing is that with the code below when i trace the clip width it gives me the right value only after 2 cliks on the thumbnails. I can’t get rid of that…
On my scene : thums container named “thumbnails”, image container named “loader”
Here’s the code:

[color=SandyBrown]_global.limitebas = -1000;
_global.limitehaut = 150;
var x_orig = 18;
var y_orig = 156;
var xSpace = 60;
var ySpace = 60;
var col = 3;
var num_col = 0;
var x_or= 395;
var b_or = 395;
var num_ligne = 0;

myPhoto = new XML();
myPhoto.ignoreWhite = true;
myPhoto.onLoad = function(success) {
//portfolioTag = this.firstChild;
numimages = this.firstChild.childNodes.length;
spacing = 120;
for (i=0; i<numimages; i++) {
picHolder = this.firstChild.childNodes*;
thumbHolder = thumbnails.createEmptyMovieClip(“thumbnail”+i, i);
if (num_col>col-1) {
num_col = 0;
num_ligne++;
}
thumbHolder._x = 12.2 +(num_colxSpace);
thumbHolder._y = 29 +(num_ligne
ySpace);
num_col++;
thumbLoader = thumbHolder.createEmptyMovieClip(“thumbnail_image”, 0);
thumbLoader.loadMovie(picHolder.attributes.thmb);
thumbHolder.main = picHolder.attributes.main;
thumbHolder.onRollOver = function () {
this._alpha = 50;
}
thumbHolder.onRollOut = function () {
this._alpha = 100;
}
thumbHolder.onRelease = function() {
loader.loadMovie(this.main);
w = loader._width;
h = loader._height;
loader._x = 390 + 350-w/2;
trace(w);
}
}
};
myPhoto.load(“beauty.xml”);

[color=Black]Any help appreciated!
Than you
[/color][/color]