Bitmap aspect ratio question

Hi Kirupa,

I found a thread in actionscript.com that resizes a bg image beautifully (without any pixelation whatsoever), except that there is a minor glitch in the script that doesn’t load properly. What does the solution mean: “try waiting until after the image is loaded. call your setBackground(); function from the onLoadInit”

Here is the script:

import flash.display.*;
// this tells Flash NOT to allow the assets to be scaled
Stage.scaleMode = “noScale”;
Stage.align = “TL”;

// need to set up a listener object to say when the stage is resized.
var stageListener:Object = new Object();
Stage.addListener(stageListener);

setBackground();

// called when the stage is resized
stageListener.onResize = function() {
setBackground();
}

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

// 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) {
mc._visible = false;
var bitmap:BitmapData = new BitmapData(mc._width, mc._height, true);
this.tmc.attachBitmap(bitmap, this.tmc.getNextHighestDepth(),“auto”, true);
bitmap.draw(mc);
};

// Do it, load the bitmap now
var loader:MovieClipLoader = new MovieClipLoader();
loader.addListener(listener);
loader.loadClip(url, bmc);
}

// Sample code

createEmptyMovieClip(“mc1”, getNextHighestDepth());
mc1.createEmptyMovieClip(“mc”, mc1.getNextHighestDepth());
//mc1.mc.loadMovie(“flash.jpg”);
loadBitmapSmoothed(“flash.jpg”, mc1.mc);
function setBackground() {

// determine middle
var middleX = Stage.width/2;
var middleY = Stage.height/2;

// scale background to fit width and height
mc1.mc._width = Stage.width;
mc1.mc._height = Stage.height;

// see if it grew bigger horizontally or vertically and adjust other to match
// to maintain aspect ratio
mc1.mc._xscale > mc1.mc._yscale ? mc1.mc._yscale = mc1.mc._xscale : mc1.mc._xscale = mc1.mc._yscale;

}
setBackground();

The full thread can be seen here:
http://www.actionscripts.org/forums/…php3?t=139207

Any help is kindly appreciated. Tks.