# Centering A Loaded Image/Movie

**URL:** https://forum.kirupa.com/t/centering-a-loaded-image-movie/185199
**Category:** flash
**Created:** [April 11, 2006, 6:05pm UTC](https://forum.kirupa.com/t/centering-a-loaded-image-movie/185199 "2006-04-11T18:05:31Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![jflint](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jflint/32/2115_2.png) [@jflint](https://forum.kirupa.com/u/jflint)
#### Post date: [April 11, 2006, 6:05pm UTC](https://forum.kirupa.com/t/centering-a-loaded-image-movie/185199/1 "2006-04-11T18:05:31Z")

</div>

[LEFT]  
[FONT=Arial][SIZE=2][COLOR=#0000ff]I am needing to load an external image (probably jpg) into a movie. I am using an empty movie clip, giving it an instance name and the code:

[/COLOR][/SIZE][/FONT]

```auto
instance1.loadMovie("image.jpg");

```

[/LEFT]  
[LEFT] [/LEFT]  
[LEFT][FONT=Arial][SIZE=2][COLOR=#0000ff]What I also need to do is be able to either place that image in a specific location on the stage or just center it. Any advice you can give me on that?

I am attempting to do something like this:[/COLOR][/SIZE][/FONT][/LEFT]  
[LEFT] [/LEFT]  
[LEFT][FONT=Arial][SIZE=2][COLOR=#0000ff]Use two movie clips. One is a holder that contains the second movie clip, which is where the image is actually being loaded. Then, I am using the following math:[/COLOR][/SIZE][/FONT][/LEFT]  
[LEFT] [/LEFT]  
[LEFT][/LEFT]

```auto
[LEFT]instance1.isntance2.x - instance1._width/2[/LEFT]
 instance1.isntance2.y - instance1._width/2
 

```

[FONT=Arial][SIZE=2][COLOR=#0000ff]Does this look like it would work? Is there anyway I can set instance1 to have a width that is equal to the size of the main movie (1024 x 768)?[/COLOR][/SIZE][/FONT]

---

<div class="post-metadata">

### Author: ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)
#### Post date: [April 11, 2006, 6:08pm UTC](https://forum.kirupa.com/t/centering-a-loaded-image-movie/185199/2 "2006-04-11T18:08:38Z")

</div>

```auto
instance1._x = (Stage.width/2)-(this._width/2)
instance1._y = (Stage.height/2)-(this._height/2)

```

🙂

---

<div class="post-metadata">

### Author: ![jflint](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jflint/32/2115_2.png) [@jflint](https://forum.kirupa.com/u/jflint)
#### Post date: [April 11, 2006, 6:38pm UTC](https://forum.kirupa.com/t/centering-a-loaded-image-movie/185199/3 "2006-04-11T18:38:40Z")

</div>

Thanks.

This will center the 0,0 point of the MC, right? Is there a way to reposition the image once it is loaded so that it is centered on the 0,0 point of the movie it is loaded into?

---

<div class="post-metadata">

### Author: ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)
#### Post date: [April 11, 2006, 6:49pm UTC](https://forum.kirupa.com/t/centering-a-loaded-image-movie/185199/4 "2006-04-11T18:49:31Z")

</div>

nope that will move that clip to the very center of the screen.

---

<div class="post-metadata">

### Author: ![jflint](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jflint/32/2115_2.png) [@jflint](https://forum.kirupa.com/u/jflint)
#### Post date: [April 11, 2006, 6:55pm UTC](https://forum.kirupa.com/t/centering-a-loaded-image-movie/185199/5 "2006-04-11T18:55:31Z")

</div>

right, but it centers the 0,0 point of the clip, right?

---

<div class="post-metadata">

### Author: ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)
#### Post date: [April 11, 2006, 6:56pm UTC](https://forum.kirupa.com/t/centering-a-loaded-image-movie/185199/6 "2006-04-11T18:56:37Z")

</div>

nope. it centers the center of the clip, regardless of it’s dimensions

---

<div class="post-metadata">

### Author: ![Catalist](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/catalist/32/2148_2.png) [@Catalist](https://forum.kirupa.com/u/Catalist)
#### Post date: [April 11, 2006, 7:00pm UTC](https://forum.kirupa.com/t/centering-a-loaded-image-movie/185199/7 "2006-04-11T19:00:16Z")

</div>

```auto
inctance1.loadMovie("image.jpg", "image1")
image1._x = 0;
image1._y = 0;
inctance1._x = Stage.width/2;
inctance1._y = Stage.height/2;

```

try that.

---

<div class="post-metadata">

### Author: ![jflint](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jflint/32/2115_2.png) [@jflint](https://forum.kirupa.com/u/jflint)
#### Post date: [April 11, 2006, 7:01pm UTC](https://forum.kirupa.com/t/centering-a-loaded-image-movie/185199/8 "2006-04-11T19:01:54Z")

</div>

Thanks.

---

<div class="post-metadata">

### Author: ![jflint](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jflint/32/2115_2.png) [@jflint](https://forum.kirupa.com/u/jflint)
#### Post date: [April 11, 2006, 8:44pm UTC](https://forum.kirupa.com/t/centering-a-loaded-image-movie/185199/9 "2006-04-11T20:44:09Z")

</div>

Odd. Every image i try and load streaks across the screen (even without the repositioning stuff).

---

<div class="post-metadata">

### Author: ![jflint](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jflint/32/2115_2.png) [@jflint](https://forum.kirupa.com/u/jflint)
#### Post date: [April 11, 2006, 9:18pm UTC](https://forum.kirupa.com/t/centering-a-loaded-image-movie/185199/10 "2006-04-11T21:18:22Z")

</div>

ok, its not centering the way that I want it to. Here is a screenshot of the swf playing, with the actionscript I am using to load the image also visible.

[http://www.jeremyflint.com/dev/screenshot.png](http://www.jeremyflint.com/dev/screenshot.png)

Here is the actionscript for reference:

```auto
image1.loadMovie("logo/image.jpg")
image1._x = (Stage.width/2)-(this._width/2)
image1._y = (Stage.height/2)-(this._height/2)

```

Thanks!

---

<div class="post-metadata">

### Author: ![jflint](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jflint/32/2115_2.png) [@jflint](https://forum.kirupa.com/u/jflint)
#### Post date: [April 11, 2006, 10:06pm UTC](https://forum.kirupa.com/t/centering-a-loaded-image-movie/185199/11 "2006-04-11T22:06:10Z")

</div>

\*bump

---

<div class="post-metadata">

### Author: ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)
#### Post date: [April 12, 2006, 4:40am UTC](https://forum.kirupa.com/t/centering-a-loaded-image-movie/185199/12 "2006-04-12T04:40:58Z")

</div>

You’ll have to wait till the picture is loaded…

```auto
function loadPicture(clip) {
	image1.loadMovie(clip);
	var temp = this.createEmptyMovieClip("temp", 8899);
	temp.onEnterFrame = function() {
		if (image1._width) {
			image1._x = Stage.width/2-image1._width/2;
			image1._y = Stage.height/2-image1._height/2;
			delete this.onEnterFrame;
		}
	};
}
loadPicture("logo/image.jpg");

```

scotty(-:

---

<div class="post-metadata">

### Author: ![jflint](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jflint/32/2115_2.png) [@jflint](https://forum.kirupa.com/u/jflint)
#### Post date: [April 12, 2006, 1:49pm UTC](https://forum.kirupa.com/t/centering-a-loaded-image-movie/185199/13 "2006-04-12T13:49:54Z")

</div>

Scotty = Actionscript Wizard
