How to use transparent BitmapData as a mask
Asked Answered
N

3

5

I have a BitmapData object created dynamically that contains user-drawn shapes. I then attach that BitmapData object to a MovieClip via a Bitmap object and set that MovieClip as a mask to another MovieClip. The mask works but the whole bounding rectangle of the BitmapData is acting as the mask. But I want to exclude the transparent portion from the mask so only user-drawn shape can be set as mask. Can anyone tell how to achieve that? Thanks.

Nonary answered 15/9, 2010 at 8:26 Comment(0)
M
9

I see you already solved it (in the comments section). Posting it as an answer.
Set BOTH movieclip and mask cacheAsBitmap to true.

i.e.:

movieclip.cacheAsBitmap = true;  
movieclip_mask.cacheAsBitmap = true;
Mythopoeic answered 3/10, 2011 at 3:3 Comment(0)
B
2

The thing you need to do is turn the bitmap caching on.

myMc.cacheAsBitmap = true; if I remember correctly ...

Bernitabernj answered 15/9, 2010 at 13:59 Comment(1)
As said above, do this on the bitmap object as well.Vermifuge
J
0

Maybe you should try using the Bitmap itself as a mask , if you need that Bitmap to show, try creating another Bitmap using the transparent BitmapData and use that as a mask.

Jornada answered 15/9, 2010 at 9:23 Comment(6)
Tried setting the Bitmap directly as the mask. No luck!Nonary
Have you tried playing with BlendMode ( forgetting about the mask I mean )?Jornada
Well, I've done it! We must set the 'cacheAsBitmap' property of both the Bitmap (that will act as the mask) and the MovieClip (on which the mask will be set) to 'true'. Otherwise the mask won't work properly.Nonary
Thanks to this post: blog.mattiasnorell.com/2010/04/16/…Nonary
Thanks mate for keeping in touch with me :)Nonary
@Kayes, thanks a lot, you should add your own solution as an answer and accept it.Augustin

© 2022 - 2024 — McMap. All rights reserved.