# Locating center of swf

**URL:** <https://forum.kirupa.com/t/locating-center-of-swf/23510>\
**Category:** Uncategorized\
**Created:** [June 18, 2003, 8:05pm UTC](https://forum.kirupa.com/t/locating-center-of-swf/23510 "2003-06-18T20:05:11Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![reverendflash](https://avatars.discourse-cdn.com/v4/letter/r/f08c70/32.png) [@reverendflash](https://forum.kirupa.com/u/reverendflash)\
**Post date:** [June 18, 2003, 8:05pm UTC](https://forum.kirupa.com/t/locating-center-of-swf/23510/1 "2003-06-18T20:05:11Z")

</div>

I have a group of images, 8 wide, 5 high, totalling 40 ( :trout: ) .

what I want to happen:

On RollOver, load MyFile.jpg into target a …

this I can do. However, here is where Gen2 was easy, MX will orient the jpg by it’s upper right corner. This won’t work, since I don’t know the orientation (landscape or portrait) because they will be dynamic…

any idea how to load into a target and orient to the center of the loaded image?

thanks in advance,

Rev ![](http://www.aulman.com/rev.gif)

---

<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 18, 2003, 8:21pm UTC](https://forum.kirupa.com/t/locating-center-of-swf/23510/2 "2003-06-18T20:21:26Z")

</div>

It’s the upper left corner that it attaches to 😉 (well depending on your view, looking at the monitor it’s upper left).

And yeah, that’s something I don’t like about dynamically loading things, you should be able to change that easily but noooo, Macromedia wanted to be difficult.

I don’t know a way off hand, but I will see if I can figure something out (unless someone else here comes up with a solution)

---

<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 18, 2003, 8:23pm UTC](https://forum.kirupa.com/t/locating-center-of-swf/23510/3 "2003-06-18T20:23:14Z")

</div>

to center the loaded image, try this: 🙂

```auto
mc = _root.movieclipwithimageinit
mc._x = (Stage.width/2)-mc._width
mc._x = (Stage.height/2)-mc._height

```

[edit]

make sure it’s excuted AFTER the image is fully loaded into the movieclip movieclipwithimageinit :A+:

---

<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 18, 2003, 8:30pm UTC](https://forum.kirupa.com/t/locating-center-of-swf/23510/4 "2003-06-18T20:30:50Z")

</div>

ahmed:

thanks, but if it is already loaded, will it jump to the center when the script is run?

I want the image to be centered on the stage on rollover…

Rev ![](http://www.aulman.com/rev.gif)

---

<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 18, 2003, 8:30pm UTC](https://forum.kirupa.com/t/locating-center-of-swf/23510/5 "2003-06-18T20:30:53Z")

</div>

I came up with this…

---

<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 18, 2003, 8:32pm UTC](https://forum.kirupa.com/t/locating-center-of-swf/23510/6 "2003-06-18T20:32:27Z")

</div>

> \*Originally posted by lostinbeta \*  
> \*\*It’s the upper left corner that it attaches to 😉 (well depending on your view, looking at the monitor it’s upper left).

And yeah, that’s something I don’t like about dynamically loading things, you should be able to change that easily but noooo, Macromedia wanted to be difficult.

I don’t know a way off hand, but I will see if I can figure something out (unless someone else here comes up with a solution) \*\*

In Gen2, I could specify to load to the center of an object…

another thing I wish they would put back in… along with dynamic png’s …

hmmmrf!

Rev

---

<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 18, 2003, 8:33pm UTC](https://forum.kirupa.com/t/locating-center-of-swf/23510/7 "2003-06-18T20:33:54Z")

</div>

Check my last post 🙂 Works fine for me. Lemme explain the code though…

[AS]  
//load the images  
container1.loadMovie(“lib\_banner1.jpg”);  
container2.loadMovie(“lib\_banner1.jpg”);  
//keep checking onEnterFrame  
this.onEnterFrame = function() {  
//if container2s width is greater than 0  
//(meaning the image was fully loaded and is now attached to the clip)  
if (container2.\_width\>0) {  
//stop running the onEnterFrame  
delete this.onEnterFrame;  
//position clip  
container2.\_x -= container2.\_width/2;  
container2.\_y -= container2.\_height/2;  
}  
};[/AS]

---

<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 18, 2003, 8:37pm UTC](https://forum.kirupa.com/t/locating-center-of-swf/23510/8 "2003-06-18T20:37:23Z")

</div>

> \*Originally posted by lostinbeta \*  
> \*\*I came up with this… \*\*

Okay, thanks lost, I get it…

I’ll let you know if I have any questions on application…

Thanks a bunch…

::I take back my harsh words about MX…although I mean it about the png’s::

Rev

---

<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 18, 2003, 8:38pm UTC](https://forum.kirupa.com/t/locating-center-of-swf/23510/9 "2003-06-18T20:38:36Z")

</div>

I think they should allow dynamic .png and .gif images (although I would personally value the dynamic .gif more than .png)

---

<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 18, 2003, 8:41pm UTC](https://forum.kirupa.com/t/locating-center-of-swf/23510/10 "2003-06-18T20:41:58Z")

</div>

I’m kinda assuming if you can dynamically load png’s, then gif’s would be a no-brainer…

Like I keep bytching about… they used to… I have 2 clients that would pay $$ to have dynamic gif’s right now… If MX2 supports it, I may get them to pay for my upgrade… 😉

thanks again for the notation on the code. Even though I figured this one out on my own, it’s nice to have on file, just in case it falls into one of those Swiss Cheese holes in my file cabinet…

Rev ![](http://www.aulman.com/rev.gif)

---

<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 18, 2003, 8:48pm UTC](https://forum.kirupa.com/t/locating-center-of-swf/23510/11 "2003-06-18T20:48:17Z")

</div>

> \*Originally posted by reverendflash \*  
> \*\*ahmed:  
> thanks, but if it is already loaded, will it jump to the center when the script is run?  
> I want the image to be centered on the stage on rollover…  
> Rev \*\*  
> this should do it 🙂

```auto
Stage = {width: 550, height:400}
mc.onRollOver = function() {
	this._x = (Stage.width/2)-this._width/2
	this._y = (Stage.height/2)-this._height/2
};

```

---

<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 19, 2003, 3:12am UTC](https://forum.kirupa.com/t/locating-center-of-swf/23510/12 "2003-06-19T03:12:02Z")

</div>

I think the problem with dynamic gifs is they can be animated. i don’t know about png’s, but it would not be as easy as it sounds to get a animated gif into flash. Gifs can have different frame durations, and flash cant even support different frame rates of dynamically loaded swfs. The plugin will be almost a fully functional browser if it starts supporting every file type, and that would not be a good thing. Not unless the plugin starts using CPU more efficiently.

It would be nice though, just to be able to get a single frame gif. I hope they read all the wish lists that are out there.

---

<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 19, 2003, 3:42am UTC](https://forum.kirupa.com/t/locating-center-of-swf/23510/13 "2003-06-19T03:42:37Z")

</div>

Well i’m sure animated gifs contain different information inside them, so it would definitely rock if Flash has the ability to weed out the different between animated and not and allow the non-animated ones.

As Rev stated before though, Generator had the ability to load in most file types dynamically, unfortunately they cut out a lot of that in Flash MX due to plug-in size restrictions ☹
