# Centering MovieClips

**URL:** https://forum.kirupa.com/t/centering-movieclips/10521
**Category:** flash
**Created:** [January 2, 2003, 6:36pm UTC](https://forum.kirupa.com/t/centering-movieclips/10521 "2003-01-02T18:36:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![AWarrenM](https://avatars.discourse-cdn.com/v4/letter/a/74df32/32.png) [@AWarrenM](https://forum.kirupa.com/u/AWarrenM)
#### Post date: [January 2, 2003, 6:36pm UTC](https://forum.kirupa.com/t/centering-movieclips/10521/1 "2003-01-02T18:36:20Z")

</div>

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…

```auto

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 😃 ) ?

Thanks All.

-Anthony

---

<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: [January 2, 2003, 11:59pm UTC](https://forum.kirupa.com/t/centering-movieclips/10521/2 "2003-01-02T23:59:34Z")

</div>

bump… anyone?

---

<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: [January 3, 2003, 12:42am UTC](https://forum.kirupa.com/t/centering-movieclips/10521/3 "2003-01-03T00:42:02Z")

</div>

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

```auto

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

```
