# \[as2\] need help centering a loaded image

**URL:** https://forum.kirupa.com/t/as2-need-help-centering-a-loaded-image/264317
**Category:** flash
**Created:** [June 24, 2008, 10:54pm UTC](https://forum.kirupa.com/t/as2-need-help-centering-a-loaded-image/264317 "2008-06-24T22:54:06Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![craigashby](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@craigashby](https://forum.kirupa.com/u/craigashby)
#### Post date: [June 24, 2008, 10:54pm UTC](https://forum.kirupa.com/t/as2-need-help-centering-a-loaded-image/264317/1 "2008-06-24T22:54:06Z")

</div>

i know i must be doing something simple wrong, but i can’t spot it. i am trying to get an empty movieclip to center after a jpg loads into it. the images load, but they don’t center. my first attempt (using loadMovie) would read the size too quickly and would only center after a second click. i thought using a MovieClipLoader would work, but my leftEdge always returns 350. i’m getting a 0 value for \_width.

on a related topic, i want to apply a DropShadowFilter to the same empty movieclip. i haven’t tried it with the MovieClipLoader, but it didn’t work using loadMovie. any ideas on that? if i have to, i can create a generic dropshadow and position and scale it accordingly, but again, i will need to be able to read the size and position of the empty movieclip.

thanks

craig

```auto
var mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mcl.addListener(mclListener);

```

```auto
function imageLoader() {
	var imgName:String = _root.section+_root.proj+"-"+_root.imgCnt+".jpg";
	mclListener.onLoadComplete = function() {
		var leftEdge:Number = (350-(_root.holder._width/2));
		_root.holder._x = leftEdge;
		trace("left side: "+leftEdge);
	};
	mcl.loadClip(imgName,_root.holder);
}

```

---

<div class="post-metadata">

### Author: ![rondog](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rondog/32/2478_2.png) [@rondog](https://forum.kirupa.com/u/rondog)
#### Post date: [June 24, 2008, 11:06pm UTC](https://forum.kirupa.com/t/as2-need-help-centering-a-loaded-image/264317/2 "2008-06-24T23:06:32Z")

</div>

yea need to do something like

target.\_X = 0 - (target.\_width / 2)

---

<div class="post-metadata">

### Author: ![craigashby](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@craigashby](https://forum.kirupa.com/u/craigashby)
#### Post date: [June 24, 2008, 11:14pm UTC](https://forum.kirupa.com/t/as2-need-help-centering-a-loaded-image/264317/3 "2008-06-24T23:14:30Z")

</div>

[QUOTE=mrwicked;2348584]yea need to do something like

target.\_X = 0 - (target.\_width / 2)[/QUOTE]

how is that different from what i did? i only broke it into 2 lines so that i could trace the leftEdge easier. i think the problem is that it is reading the width of the empty\_mc rather than the width of the jpg i am loading into it. or maybe i’m misunderstanding you.

```auto
var leftEdge:Number = (350-(_root.holder._width/2));
**_root.holder._x = leftEdge;
**trace("left side: "+leftEdge);

```

---

<div class="post-metadata">

### Author: ![rondog](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rondog/32/2478_2.png) [@rondog](https://forum.kirupa.com/u/rondog)
#### Post date: [June 24, 2008, 11:22pm UTC](https://forum.kirupa.com/t/as2-need-help-centering-a-loaded-image/264317/4 "2008-06-24T23:22:03Z")

</div>

well first use the onLoadInit function rather than onLoadComplete. Change 350 to a 0 and see if it works. I don’t understand how you think what you did is the same as mine. The concept is the same, but the values sure aren’t, unless I didn’t understand your initial post.

If its returning 0 for your width, then changing onLoadComplete to onLoadInit should return the correct width.

---

<div class="post-metadata">

### Author: ![craigashby](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@craigashby](https://forum.kirupa.com/u/craigashby)
#### Post date: [June 25, 2008, 12:05am UTC](https://forum.kirupa.com/t/as2-need-help-centering-a-loaded-image/264317/5 "2008-06-25T00:05:27Z")

</div>

OnLoadInit fixed it. the centering works now. i wasn’t clear on it’s usage.

the reason i am using 350 instead of 0, is that it needs to center at 350. 0 would put the left half of the image off screen. i wasn’t clear in my first post.

thanks for your help.

ps: my DropShadowFilter works now too. you and Init rule.

---

<div class="post-metadata">

### Author: ![rondog](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rondog/32/2478_2.png) [@rondog](https://forum.kirupa.com/u/rondog)
#### Post date: [June 25, 2008, 4:43am UTC](https://forum.kirupa.com/t/as2-need-help-centering-a-loaded-image/264317/6 "2008-06-25T04:43:27Z")

</div>

awesome man
