Resizing dynamically loaded images

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 :frowning:

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


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);

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.


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