# Centering Image within resizing frame

**URL:** <https://forum.kirupa.com/t/centering-image-within-resizing-frame/32189>\
**Category:** flash\
**Created:** [October 2, 2003, 5:50pm UTC](https://forum.kirupa.com/t/centering-image-within-resizing-frame/32189 "2003-10-02T17:50:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![samoan\_joe](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@samoan\_joe](https://forum.kirupa.com/u/samoan_joe)\
**Post date:** [October 2, 2003, 5:50pm UTC](https://forum.kirupa.com/t/centering-image-within-resizing-frame/32189/1 "2003-10-02T17:50:16Z")

</div>

Im having problems of centering my images dead center of my resizing frame. Can someone help me to adjust this?

cheers:)

heres the code:

// All the credits go to Gorlim from [www.flashxpress.net](http://www.flashxpress.net)  
// You need 2 clips in the library: btn and fond

cmpt = 0; //handles depth to attach  
maxWidth =400; //of an image  
maxHeight = 400; //of an image  
nbEtapes = 20; //nb of steps for the resize  
images = [“image1”,“image2”, “image3”, “image4”,“image5”,“image6”]; //names of the pics without “.jpg”

this.attachMovie(“fond”,“fond”, cmpt++);

//loadJpg called when you click a button  
loadJpg = function () {  
jpg.\_xscale = jpg.\_yscale=100;  
//load the file corresponding to the button  
jpg.loadMovie(images[Number(this.\_name.substr(3))]+".jpg");  
//check the loading  
fond.onEnterFrame = function() {  
if (jpg.getBytesTotal()\>0 && jpg.getBytesLoaded() == jpg.getBytesTotal()) {  
// it’s over. We hide the pic until the end of the resize  
jpg.\_visible = false;  
// resize the image if pic too big  
if (jpg.\_width\>maxWidth || jpg.\_height\>maxHeight) {  
jpg.\_xscale = jpg.\_yscale=Math.min(100_maxWidth/jpg.\_width, 100_maxHeight/jpg.\_height);  
}  
// total width of the container  
fondWidth = jpg.\_width+btns.\_width+30;  
// increment  
deltaX = Math.round((fondWidth-fond.\_width)/nbEtapes);  
fondWidth=deltaX\*nbEtapes+fond.\_width;  
deltaY = Math.round((jpg.\_height+20-fond.\_height)/nbEtapes);

```
                     // actual resize
                     jpg.onEnterFrame = function() {
                             if ((fond._width&lt;fondWidth && deltaX&gt;0) || (fond._width&gt;fondWidth && deltaX&lt;0)) {
                                     fond._width += deltaX;
                                     fond._height += deltaY;
                                     btns._x = fond._width-btns._width+20;
                             } else {
                                     //resize over, delete onEnterFrame of the resize
                                     this._visible = true;
                                     delete this.onEnterFrame;
                             }
                     };
             }
             // delete the onEnterframe of the load
             delete this.onEnterFrame;
     };

```

};

// container of the buttons  
this.createEmptyMovieClip(“btns”, cmpt++);  
btns.\_x = btns.\_y=10;  
for (var i = 0; i\<images.length; i++) {  
btns.attachMovie(“btn”, “btn”+i, i, {\_y:20_i, image:images_, onRelease:loadJpg});  
}

// container of the pics  
this.createEmptyMovieClip(“jpg”, cmpt++);  
jpg.\_x = jpg.\_y=10;  
Report this post to a moderator | IP: Logged
