PDA

View Full Version : [FMX] Gallery->centering main image



bobota
July 8th, 2005, 12:33 PM
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 350*350 if the image width or height is <350.I have 3 sorts of image size : 350*350, <350*350, 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:

_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[i];
thumbHolder = thumbnails.createEmptyMovieClip("thumbnail"+i, i);
if (num_col>col-1) {
num_col = 0;
num_ligne++;
}
thumbHolder._x = 12.2 +(num_col*xSpace);
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");

Any help appreciated!
Than you

scotty
July 9th, 2005, 01:13 AM
You can retrieve the right width and height after the image is fully loaded...

scotty(-:

bobota
July 9th, 2005, 07:39 AM
but how to do that? isn't that it was doing in the on release button?

stringy
July 9th, 2005, 07:43 AM
but how to do that? isn't that it was doing in the on release button?
No, you need to set up a loop to check getBytesLoaded()/getBytesTotal(), just like a preloader.

scotty
July 9th, 2005, 08:59 AM
//change xcenter and ycenter to your needs
var xcenter = 400;
var ycenter = 300;
function preload(clip) {
loader.loadMovie(clip);
var temp = this.createEmptyMovieClip("temp", 9965);
temp.onEnterFrame = function() {
if (loader.getBytesLoaded() == loader.getBytesTotal() && loader._width>0 && loader._height>0) {
loader._x = xcenter-loader._width/2;
loader._y = ycenter-loader._height/2;
delete this.onEnterFrame;
}
};
}
//in your for loop
thumbHolder.onRelease = function() {
preload(this.main);
};

scotty(-:

stringy
July 9th, 2005, 09:12 AM
//change xcenter and ycenter to your needs
var xcenter = 400;
var ycenter = 300;
function preload(clip) {
loader.loadMovie(clip);
var temp = this.createEmptyMovieClip("temp", 9965);
temp.onEnterFrame = function() {
if (loader.getBytesLoaded() == loader.getBytesTotal() && loader._width>0 && loader._height>0) {
loader._x = xcenter-loader._width/2;
loader._y = ycenter-loader._height/2;
delete this.onEnterFrame;
}
};
}
//in your for loop
thumbHolder.onRelease = function() {
preload(this.main);
};

scotty(-:

Looks like you have done that before Scotty ;)

bobota
July 9th, 2005, 11:00 AM
thank you very much scotty! i thought things like that but didn't know what to write.

scotty
July 9th, 2005, 03:20 PM
Looks like you have done that before Scotty ;)
:lol: what made you think that...;)

no problem, bobota :)

scotty(-: