rss twitter

Alpha / Soft Masks in Actionscript

We're all used to the fact that the Flash IDE doesn't support soft masks for any reason. Everyone needing soft / alpha gradient masks must use Actionscript to realize that. Just add a PNG (you want to use as map) with transparency to your library (or load it), export it for Actionscript (in our case it's MaskPNG) and then use the following code (mcToBeMasked is already on stage). What's essential is the cacheAsBitmap - property which will dither the png with transparency:

Actionscript:
  1. var png:MaskPNG = new MaskPNG(200, 200);
  2. var maskBitmap = new Bitmap(png, PixelSnapping.AUTO);
  3. maskBitmap.cacheAsBitmap = true;
  4. addChild(maskBitmap);
  5.  
  6. mcToBeMasked.cacheAsBitmap = true;
  7. mcToBeMasked.mask = maskBitmap;

Leave a Reply

Powered by WordPress | Free T-Mobile Phones for Sale | Thanks to Palm Pre Blog, Video Game Music and Get Six Pack Abs