Archive for March, 2009

Using a timeline animation as alpha mask

I guess you know, that you have to set the cacheAsBitmap property of both, the mask and the masked Sprite, to apply an alpha mask.

...
mask.cacheAsBitmap = true;
container.mask = mask;
container.cacheAsBitmap = true;
...

This works perfectly with a static bitmap mask but if you try to do the same with an animated MovieClip mask, the mask will not work anymore. Apparently the cacheAsBitmap property of the MovieClip is reset on entering a new frame and therefore to get it working you have to set cacheAsBitmap = true in every frame.

...
mask.cacheAsBitmap = true;
container.mask = mask;
container.cacheAsBitmap = true;
 
addEventListener(Event.ENTER_FRAME, frameHandler);
 
function frameHandler(event : Event) : void
{
	mask.cacheAsBitmap = true;
}
 
...

About

Martin Rädlinger is an Interactive Developer & Designer. He specializes in interactive coding predominantly with ActionScript, but every new challenge is welcome. If you like his work feel free to get in touch with him. At the moment he's available for freelance work.

Contact

Martin Rädlinger
mail: mr [at] formatlos.de
web: www.formatlos.de
xing: Martin Rädlinger
linkedin: Martin Rädlinger
skype: martinraedlinger