onClipEvent enterFrame stop loop problem

I wasn’t sure how to name this thread to well. Ah well. Here’s my funk:
I have made a photo slide show and all works well for browsing and viewing. Where I got stuck was when I tried to write code that would center images that were vertical. This is the entire code on the empty mc that has it preload, display then adjust the x of the image. Now, with this code if the image is vertical it flies off the right of the page. haha. sounds fun eh?

onClipEvent (enterFrame) {
	total_bytes = this.getBytesTotal();
	loaded_bytes = this.getBytesLoaded();
	remaining_bytes = total_bytes-loaded_bytes;
	percent_done = int((loaded_bytes/total_bytes)*100);
	if (total_bytes == loaded_bytes) {
		if (this._width<this._height) {
				this._x = this._x+(this._width/2);
		} else {
			this._x = 149.8;

I’ve been playing around with a few alternatives to stop the loop once it has changed the _x position but haven’t figured out the best way. I’ll figure it out sooner or later but i find whenever i post on here someone tends to beat me :smirk:. Ok, well thanks in advance to anyone who can help out. The race is on! :bad:

You need to get the height and width of the stage and divide them by 2. This is the center of the stage.
Then get the height and width of the picture (in this case this._width and this._height) and divide that by two too. This is the center of the picture.

Then just subtract the width and hieght of the container from the stage width and height values. Make sure the registration point of the container is in the middle.

a = stage.width/2;
b = stage.height/2;

c = this._width/2;
d = this.height/2;

this._x = a - c;
this._y = b - d;

At least I think thats how I did it.

Oh, and then just add your x offset (150 instead of 149.8 put your container on a whole pixel for super nice pics!)

hhaha you beat me to it! it happens every time i post a question. thank you so much for your feedback and yes that is the way to do it. now my photo gallery is completely dynamic!! i can’t believe it! ok, well thanks a bunch and i moved the empty clip to 150. mmmmm the pics do look nice :beam: thank you Ordinathorreur!!

Excellent :thumb: