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;
}
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.
6 Comments
1 lukegill wrote:
This is brilliant! Thanks very much...i'll use it loads...why wasn't this implemented at part of the MovieClipLoader class???
2 Non Cho wrote:
Use this when the external image is loaded:
forceSmoothing (MovieClip.forceSmoothing property)
3 gyo wrote:
That's cool Non Cho, thanks! I'll try it out and let you know!
4 Mads ny wrote:
nice little function saved me 10 min of coding hihi and borring google search.
but i noticed that these two lines should be flipe
mc.attachBitmap(bitmap, 0, "auto", true);
bitmap.draw(mc);
you should draw the existing data into the bitmap data object before redrawing the Movieclip, otherwise you'll get a blank mc
happy coding
5 pradeep wrote:
can you give me souce fla?
6 gyo wrote:
Hi Pradeep,
I updated the post, you'll find the example at the end.
Just use the 'forceSmoothing" property in the onLoad event.
Hope it helps!