# onClipEvent enterFrame stop loop problem

**URL:** <https://forum.kirupa.com/t/onclipevent-enterframe-stop-loop-problem/113228>\
**Category:** Uncategorized\
**Created:** [June 16, 2004, 3:52am UTC](https://forum.kirupa.com/t/onclipevent-enterframe-stop-loop-problem/113228 "2004-06-16T03:52:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![enriquepr](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/enriquepr/32/459_2.png) [@enriquepr](https://forum.kirupa.com/u/enriquepr)\
**Post date:** [June 16, 2004, 3:52am UTC](https://forum.kirupa.com/t/onclipevent-enterframe-stop-loop-problem/113228/1 "2004-06-16T03:52:23Z")

</div>

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?

```auto

onClipEvent (enterFrame) {
	total_bytes = this.getBytesTotal();
	loaded_bytes = this.getBytesLoaded();
	remaining_bytes = total_bytes-loaded_bytes;
	percent_done = int((loaded_bytes/total_bytes)*100);
	_root.loaderim.gotoAndStop(percent_done);
	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 😏. Ok, well thanks in advance to anyone who can help out. The race is on! :bad:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 4:44am UTC](https://forum.kirupa.com/t/onclipevent-enterframe-stop-loop-problem/113228/2 "2004-06-16T04:44:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 4:49am UTC](https://forum.kirupa.com/t/onclipevent-enterframe-stop-loop-problem/113228/3 "2004-06-16T04:49:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 7:39am UTC](https://forum.kirupa.com/t/onclipevent-enterframe-stop-loop-problem/113228/4 "2004-06-16T07:39:33Z")

</div>

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!!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 3:18pm UTC](https://forum.kirupa.com/t/onclipevent-enterframe-stop-loop-problem/113228/5 "2004-06-16T15:18:09Z")

</div>

Excellent :thumb:
