Centering MovieClips

Hey all,

(searched for awhile and couldn’t find anything…)
I’m have a photo gallery with 20 thumbnails and each thumbnail loads a .jpg image dynamically. Each .jpg has a different height and width and I want to center each of these images on a certain part of the page. How can I go about this?

I was initially thinking that I could get the height and width of each image and then calculate the center that I want by placing the image in the appropriate x y coordinates, but it looks like Flash doesn’t have the functionality to obtain the dynamically loaded jpg’s height and width…


for( i = 0; i < numThumbs ; i++ ) {
	thumbNames* = "thumb" + (i+1);
}
var bigThumb = _root.createEmptyMovieClip("big",0);
for( i = 0; i < numThumbs ; i++ ) {
	var action,m;
	action = bigThumb.createEmptyMovieClip( i + 1, i + 1);
	action._x = x_start + (30 * i);
	action._y = y;
	m = action.createEmptyMovieClip( i, i + 1 );
	m.loadMovie("erik//reportage//thumbs//erik_repThumb" + (i+1) + ".jpg");
	
	//button action
	action.onRollOver = function() {
		unloadMovie("initial");
		var pic;
		pic = _root.createEmptyMovieClip("loaded_pic", 1);
		pic._x = 220;
		pic._y = 100;
		pic.loadMovie("erik//reportage//erik_rep" + this._name + ".jpg");
		this._alpha = 40;
	}
	action.onRollOut = function() {
		this._alpha = 100;
	}
	
}

Any suggestions on how I can center (not stage center, but my own center :smiley: ) ?

Thanks All.

-Anthony

bump… anyone?

once the jpg is loaded into the movieclip you load it into, that movieclip becomes the _width and _height of the image which was loaded. That being the case, once the image has loaded, all you need to do is something like

loadedImageHolder._x -= loadedImageHolder._width/2;
loadedImageHolder._y -= loadedImageHolder._height/2;

So what you can do (and I havent really looked at your code so I dont know whats going on there exactly) is have an enterFrame check to see if the image has loaded, and if so, then center. Something to the effect of


onClipEvent(load){
	h = this.createEmptyMovieClip("holder",1);
	h.loadMovie("image.jpg");
}
onClipEvent(enterFrame){
	if (!h.loaded && h.getBytesLoaded() > 0 && h.getBytesLoaded() == h.getBytesTotal()){
		h._x -= h._width/2;
		h._y -= h._height/2;
		h.loaded = true
	}
}