Dynamic Image Resize + BitmapData Smoothing = Problem

Hello, I’m brand new to the forums here. I’m okay at actionscript, but honestly everything I’m trying to pull off is beyond me so the fact that I’ve gotten as far as I have is kind of a feat in itself. Anyway, I’m creating a dynamic image gallery that resizes the images to fit the gallery size, and then smooths them out.

I feel like I’m super close to getting it to work perfectly. The image smoothing always works, but the resizing is kind of iffy. The first image displayed will resize just fine, but when you view any others they’re all distorted or squashed. What’s strange is that I’ve traced out the resized image dimensions and they’re exactly what they should be, but the images are still not resizing correctly.

Here’s my code! I only included the parts of it that are really relevant, but let me know if you guys want to see all of it. It’s a combination of a few tutorials that I found. I may be able to provide a live example, but it’s for work so I’m not sure how the nondisclosure agreement would affect that.

Thank you so much in advance!


var thisWidth:Number;
var thisHeight:Number;
var maximumHeight:Number;//height to which movieclip to be resized
var maximumWidth:Number;//width to which movieclip to be resized
var oldx:Number;
var oldy:Number;
var ratio:Number;
var mclis:Object = new Object();//An object that listens for a callback notification from the MovieClipLoader event handlers.


function nextImage() {
    if (p<(total-1)) {
        p++;
        if (loaded == filesize) {
            picture._alpha = 0;
            loadBitmapSmoothed(image[p], picture);
            slider.cap_txt.text = "Photo By: " + author[p];
            slider.desc_txt.text = caption[p];
            header_txt.text = header[p];
            picture_num();
            trace(current_pos);
            if (sliderval == 1){
            var xPosT:Tween = new Tween(slider, "_y", Regular.easeOut, slider._y, 235, .5, true);
        sliderval = 0;
        }
        }
    }
}
function lastImage() {
        //p++;
            p = total-1;
            picture._alpha = 0;
            loadBitmapSmoothed(image[p], picture);
            slider.cap_txt.text = "Photo By: " + author[p];
            slider.desc_txt.text = caption[p];
            header_txt.text = header[p];
            picture_num();
            trace(current_pos);
            if (sliderval == 1){
            var xPosT:Tween = new Tween(slider, "_y", Regular.easeOut, slider._y, 235, .5, true);
        sliderval = 0;
        }
}
function prevImage() {
    if (p>0) {
        p--;
        picture._alpha = 0;
        loadBitmapSmoothed(image[p], picture);
        delete _root.mc;
        slider.cap_txt.text = "Photo By: " + author[p];
        slider.desc_txt.text = caption[p];
        header_txt.text = header[p];
        picture_num();
        trace(current_pos);
        if (sliderval == 1){
            var xPosT:Tween = new Tween(slider, "_y", Regular.easeOut, slider._y, 235, .5, true);
        sliderval = 0;
        }
    }
}
function firstImage() {
    if (loaded == filesize) {
        picture._alpha = 0;
        loadBitmapSmoothed(image[0], picture);
        slider.cap_txt.text = "Photo By: " + author[0];
        slider.desc_txt.text = caption[0];
        header_txt.text = header[0];
        picture_num();
        if (sliderval == 1){
            var xPosT:Tween = new Tween(slider, "_y", Regular.easeOut, slider._y, 235, .5, true);
        sliderval = 0;
        }
    }
}

function picture_num() {
    current_pos = p+1;
    pos_txt.text = current_pos+" / "+total;
}

/////////////////////////////////////

function loadBitmapSmoothed(url:String, target:MovieClip) {
    
    // Create a movie clip which will contain our unsmoothed bitmap
    var bmc:MovieClip = target.createEmptyMovieClip("bmc",target.getNextHighestDepth());

    // Create a listener which will notify us when the bitmap loaded successfully
    var listener:Object = new Object();
    // Track the target
    listener.tmc = target;
    
    // If the bitmap loaded successfully we redraw the movie into
    // a BitmapData object and then attach that BitmapData to the target
    // movie clip with the smoothing flag turned on.
    listener.onLoadInit = function(mc:MovieClip) {
        bitmap.dispose();
        _root.thisHeight = mc._height;//loaded movieclip height
        _root.maximumHeight = 500;
        _root.thisWidth = mc._width;//loaded movieclip width
        _root.maximumWidth = 304;
        
        ratio = thisHeight/thisWidth;//calculation ratio to which resize takes place
        

        if (thisWidth>maximumWidth) {
        //picture._x = 143-(thisWidth/2);
        thisWidth = maximumWidth;
        thisHeight = Math.round(thisWidth*ratio);
        width_txt.text = thisWidth;
        height_txt.text = thisHeight;
        }
        if (thisHeight>maximumHeight) {
        //picture._x = 143-(thisWidth/2);
        thisHeight = maximumHeight;
        thisWidth = Math.round(thisHeight/ratio);
        width_txt.text = thisWidth;
        height_txt.text = thisHeight;
        }
        
        picture._width = thisWidth;//applying new width
        picture._height = thisHeight;//applying new height
        //picture._xscale = 60;
        //picture._yscale = 60;
        //picture._y = -20;
        
        mc._visible = false;
        bitmap = new BitmapData(mc._width, mc._height, true);
        this.tmc.attachBitmap(bitmap, this.tmc.getNextHighestDepth(),"auto", true);
        bitmap.draw(mc);
    
    };
    
    var loader:MovieClipLoader = new MovieClipLoader();
    loader.addListener(listener);
    loader.loadClip(url, bmc);
    
//    var mcl:MovieClipLoader = new MovieClipLoader();//MovieClipLoader class lets you implement listener callbacks that provide status information while SWF, JPEG, GIF, and PNG files are being loaded into movie clips.
//    mcl.addListener(mclis);//add the object as listener for event handlers
//    _root.createEmptyMovieClip("holder_mc", _root.getNextHighestDepth());//holder movieclip
//    _root.mcl.loadClip("http://www.atpm.com/11.02/nature/images/blue-flower.jpg", _root.holder_mc);//You can use the loadClip() method to load one or more files into a single movie clip or level;
    
    
};