# Dynamically centering a MovieClip on load

**URL:** <https://forum.kirupa.com/t/dynamically-centering-a-movieclip-on-load/25693>\
**Category:** Uncategorized\
**Created:** [July 15, 2003, 8:29pm UTC](https://forum.kirupa.com/t/dynamically-centering-a-movieclip-on-load/25693 "2003-07-15T20:29:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![georges](https://avatars.discourse-cdn.com/v4/letter/g/bcef8e/32.png) [@georges](https://forum.kirupa.com/u/georges)\
**Post date:** [July 15, 2003, 8:29pm UTC](https://forum.kirupa.com/t/dynamically-centering-a-movieclip-on-load/25693/1 "2003-07-15T20:29:45Z")

</div>

Hey guys,

This is my first question to [Kirupa.com](http://Kirupa.com) 🙂

Here’s my function:

[AS]  
leftBnd = 100;  
rightBnd = 730;  
topBnd = 15;  
lowBnd = 360;

insertMovie = function(swf){  
with(\_root){  
emptyClip.unloadMovie();  
emptyClip.\_visible = false;  
emptyClip.loadMovie(swf);

```
	trace("width: " + emptyClip._width);
	trace("height: " + emptyClip._height);
	
	xpos = (rightBnd-leftBnd)-emptyClip._width;
	xpos = (xpos/2) + leftBnd;
	trace("x: " + xpos);

	ypos = (lowBnd-topBnd)-emptyClip._height;
	ypos = (ypos/2) + topBnd;
	trace("y: " + xpos);

	emptyClip._x = xpos;
	emptyClip._y = ypos;

	emptyClip._visible = true;
}

```

}  
[/AS]

Now, the first time this function is executed I get 0 and 0 for the emptyClip’s width and height even though it has run loadMovie(). Why is this? I would think that it would return the width and height of the newly loaded movie… because of this erroneous width and height the movie doesn’t center correctly unless the function is run twice to load the same movie.

The second time it is run it returns the w and h of the first loaded movie…

the third time it returns the w and h of the second movie, etc, etc.

Any help?

thanks

georges

---

<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:** [July 16, 2003, 5:53am UTC](https://forum.kirupa.com/t/dynamically-centering-a-movieclip-on-load/25693/2 "2003-07-16T05:53:14Z")

</div>

make it’s reg point in the middle and set it’s \_x to Stage.width/2  
and \_y to Stage.height

---

<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:** [July 16, 2003, 5:54am UTC](https://forum.kirupa.com/t/dynamically-centering-a-movieclip-on-load/25693/3 "2003-07-16T05:54:39Z")

</div>

see this:

[http://www.kirupaforum.com/forums/showthread.php?threadid=26238&highlight=stage](http://www.kirupaforum.com/forums/showthread.php?threadid=26238&highlight=stage) 🙂

---

<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:** [July 16, 2003, 6:35pm UTC](https://forum.kirupa.com/t/dynamically-centering-a-movieclip-on-load/25693/4 "2003-07-16T18:35:23Z")

</div>

Alright, those are some pretty interesting answers and they helped me, but I still have a problem.

The SWFs that I’m loading in seem to have different relative points on which they center. How does one set the registration point on a MovieClip?

Some SWFs seem to center relative to upper-left corner, some relative to upper-center point. One even centers relative to lower-center! 🙂

Any tips?

---

<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:** [July 20, 2003, 1:29pm UTC](https://forum.kirupa.com/t/dynamically-centering-a-movieclip-on-load/25693/5 "2003-07-20T13:29:43Z")

</div>

align window…
