Friday, December 19, 2008

AS3 Smooth Loaded Bitmaps

Loaded bitmaps (jpgs, pngs, etc) look bad in flash when scaling unless you smooth them. This function seems to replicate the bitmap "smoothng" setting in the library pallette. I still see tons of FLash sites out there that arent aware of this awesome setting. It makes bitmaps look great when they scale.

//create a new loader object and put it on the stage
var slideLoader:Loader=new Loader();

//load picture into loader object
slideLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, scaleContentForPicture);
slideLoader.load(new URLRequest("images/tree.jpg"));

//smooth it once loaded
function scaleContentForPicture() {
var smoother_bm=Bitmap(slideLoader.content);


Anonymous said...

You posted this in the nick of time! just saved me some time.

ear said...

Thanks man -- appreciate the quick line of code that saves 20 minutes of reading.