# Centering dynamically loaded jpg's

**URL:** https://forum.kirupa.com/t/centering-dynamically-loaded-jpgs/81418
**Category:** Uncategorized
**Created:** [March 2, 2005, 11:24am UTC](https://forum.kirupa.com/t/centering-dynamically-loaded-jpgs/81418 "2005-03-02T11:24:00Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Hitby](https://avatars.discourse-cdn.com/v4/letter/h/dfb087/32.png) [@Hitby](https://forum.kirupa.com/u/Hitby)
#### Post date: [March 2, 2005, 11:24am UTC](https://forum.kirupa.com/t/centering-dynamically-loaded-jpgs/81418/1 "2005-03-02T11:24:00Z")

</div>

Hi all,  
I have some code that loads jpegs from a folder into a movie clip but as you all know the registration point is 0,0 or top left. All my images are different sizes and a combo of landscape and portrait and I’d like them to all load centrally but I can’t figure out how to do it.  
I did try a work around where I converted them to png’s with transparency so that thhe image appeared central although flash won’t load the png’s.  
I’ve included the code and would be very grateful for any help

\<–  
this.pathToPics = “…/Images/comm\_lg/”;  
// fill this array with your pics  
this.pArray = [“image\_01.jpg”, “image\_02.jpg”, “image\_03.jpg”, “image\_04.jpg”, “image\_05.jpg”, “image\_06.jpg”, “image\_07.jpg”, “image\_08.jpg”, “image\_09.jpg”, “image\_10.jpg”, “image\_11.jpg”, “image\_12.jpg”, “image\_13.jpg”, “image\_14.jpg”, “image\_15.jpg”, “image\_16.jpg”, “image\_17.jpg”, “image\_18.jpg”, “image\_19.jpg”, “image\_20.jpg”, “image\_21.jpg”, “image\_22.jpg”, “image\_23.jpg”, “image\_24.jpg”, “image\_25.jpg”, “image\_26.jpg”, “image\_27.jpg”, “image\_28.jpg”];  
this.fadeSpeed = 20;  
this.pIndex = 0;  
// MovieClip methods ----------------------------------  
// d=direction; should 1 or -1 but can be any number  
//loads an image automatically when you run animation  
loadMovie(this.pathToPics+this.pArray[0], \_root.photo);  
MovieClip.prototype.changePhoto = function(d) {  
// make sure pIndex falls within pArray.length  
this.pIndex = (this.pIndex+d)%this.pArray.length;  
if (this.pIndex\<0) {  
this.pIndex += this.pArray.length;  
}  
this.onEnterFrame = fadeOut;  
};  
MovieClip.prototype.fadeOut = function() {  
if (this.photo.\_alpha\>this.fadeSpeed) {  
this.photo.\_alpha -= this.fadeSpeed;  
} else {  
this.loadPhoto();  
}  
};  
MovieClip.prototype.loadPhoto = function() {  
// specify the movieclip to load images into  
var p = \_root.photo;  
//------------------------------------------  
p.\_alpha = 0;  
p.loadMovie(this.pathToPics+this.pArray[this.pIndex]);  
this.onEnterFrame = loadMeter;  
};  
MovieClip.prototype.loadMeter = function() {  
var i, l, t;  
l = this.photo.getBytesLoaded();  
t = this.photo.getBytesTotal();  
if (t\>0 && t == l) {  
this.onEnterFrame = fadeIn;  
} else {  
trace(l/t);  
}  
};  
MovieClip.prototype.fadeIn = function() {  
if (this.photo.\_alpha\<100-this.fadeSpeed) {  
this.photo.\_alpha += this.fadeSpeed;  
} else {  
this.photo.\_alpha = 100;  
this.onEnterFrame = null;  
}  
};  
–\>

Cheers  
Hitby
