Here is a simple function to set the "Allow smoothing" images property at run-time in Flash.
Let's say you have a blank MovieClip named target_mc and you load an external image, it will be rendered without anti-alias/smoothing; I needed it to be smooth for a full-browser background story and the support for transparent images was a must, so here we go:


function smooth(mc:MovieClip)
{
var bitmap:BitmapData = new BitmapData(mc._width, mc._height, true, 0x000000);
mc.attachBitmap(bitmap, 0, "auto", true);
bitmap.draw(mc);
}

To use it, just call the function pointing to the target mc:

smooth(target_mc);

As you can see from the code, the function doesn't load anything, it just re-draws a MovieClip with the "Allow smoothing" property set; this is because I needed a quick and simple function to render any MovieClip, since I use another library to handle the loading process.

Note: The code is actionscript2. I didn't investigate the actionscript3 behavior about this issue, if you know something please drop a comment!

IMPORTANT UPDATE
I tried what Non Cho suggested and it works for Flash Player 8! Thanks man!
You no longer need the smooth() function, just keep it in case you need to export for Flash Player 7.
All you have to do is to apply the forceSmoothing property to a MovieClip after the content (image or whatever) has finished loading:


mc.forceSmoothing = true;

Remember to set the forceSmoothing property to true only AFTER the content of the MovieClip has been completely loaded. This is very important, otherwise it will not work.

One more example could be:

mc.loadMovie("my_picture.jpg");

mc.onLoad = function()
{
this.forceSmoothing = true;
}

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Twitter
  • StumbleUpon
  • Google Bookmarks
  • Technorati
  • Netvibes
  • LinkedIn
  • Live
  • Reddit
  • RSS

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.