# Resizing dynamically loaded images

**URL:** <https://forum.kirupa.com/t/resizing-dynamically-loaded-images/261599>\
**Category:** flash\
**Created:** [May 29, 2008, 6:05am UTC](https://forum.kirupa.com/t/resizing-dynamically-loaded-images/261599 "2008-05-29T06:05:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julie2008](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@Julie2008](https://forum.kirupa.com/u/Julie2008)\
**Post date:** [May 29, 2008, 6:05am UTC](https://forum.kirupa.com/t/resizing-dynamically-loaded-images/261599/1 "2008-05-29T06:05:40Z")

</div>

Hi, I’m trying to make sure that no matter what size image is uploaded, it ends up the right size in the Flash loader.

The code below does nothing to the image. At the moment without .\_width and .\_height a large image loads to fit the loader first time but when the site is refreshed, it reverts back to the images original size making it to large for the holder. Please help me ☹

How do I lock an image size to 160x255 when I’m loading it into a loader via LoadVars

```auto

var URL = "http://www.myimages.com";
image = new LoadVars();
image.onLoad = function(success) {
    if (success){
        var images = this.images;

        _root.MC_Image.contentPath=image;
       image._width=160;
       image._height=255;
        
    } else trace("Error loading")
};
image.load(URL);

```

---

<div class="post-metadata">

**Author:** ![Julie2008](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@Julie2008](https://forum.kirupa.com/u/Julie2008)\
**Post date:** [May 30, 2008, 1:56am UTC](https://forum.kirupa.com/t/resizing-dynamically-loaded-images/261599/2 "2008-05-30T01:56:50Z")

</div>

I found the code I made it adjust 10 images to 180px by 255px just add to onLoad section. And make sure you adjust the image size before you load the image into the loader or else you will see the large image then it becomes the right size.

```auto

function resize() {
        for(var i:Number=0; i<=10; i++) {

        var maxWidth = 180;
        var maxHeight = 255;
        var scaleFactor = images*._width>images*._height ? maxHeight/images*._height : maxHeight/images*._height;
        images*._yscale = scaleFactor*100;
        images*._xscale = images*._yscale;

        }    
    };

```

This code works out the scale percentage needed then adjust the image accordingly
