# Resize image at Flash....(dynamic)

**URL:** <https://forum.kirupa.com/t/resize-image-at-flash-dynamic/181805>\
**Category:** flash\
**Created:** [March 13, 2006, 9:06am UTC](https://forum.kirupa.com/t/resize-image-at-flash-dynamic/181805 "2006-03-13T09:06:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjorge](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@mjorge](https://forum.kirupa.com/u/mjorge)\
**Post date:** [March 13, 2006, 9:06am UTC](https://forum.kirupa.com/t/resize-image-at-flash-dynamic/181805/1 "2006-03-13T09:06:22Z")

</div>

I have a movieClip (empty) which is used has a placeholder to load external images. I need to fix the max size of that placeHolder to 367_367 values, so that if the image has 500_400 it will shrink to 367\*294 when loaded…And so i used the following code at the placeHolder:

```auto
onClipEvent (data) {
        loaded = 1;
        var maxWidth = 367;
        var maxHeight = 367;
        if (this._width > maxWidth || this._height > maxHeight)
        {
                var scaleFactor = this._width > this._height ? maxWidth / this._width : maxHeight / this._height;
                this._width = Math.floor (this._width * scaleFactor);
                this._height = Math.floor (this._height * scaleFactor);
        }
        if (this._height > maxHeight)
        {
                var scaleFactor = maxHeight / this._height;
                this._width = Math.floor (this._width * scaleFactor);
                this._height = Math.floor (this._height * scaleFactor);
        }
}

```

The problem is that this only works the first time i load an image. After that the images appear much smaller … Can anyone help with the code please?

Thks.
