PDA

View Full Version : masking problem



sebrofm
May 8th, 2009, 01:06 PM
hey guys, so i am having trouble getting a png(in bitmapdata form) from my library to mask a sprite that is loaded into the movie via loader.

so my setup is:
mainThumb : Sprite //empty sprite to contain bitmap loaded via loader
thumbMask : Sprite //sprite from the library that contains a png to be used as a mask for mainThumb
overlay : Bitmap //some effects to overlay image
thumb : Bitmap //bitmap loaded using loader to be added to mainThumb

from library:
Thumb_Mask : Sprite //the sprite in the library containing the png
Thumb_Overlay : BitmapData

and the code (that isn't working)



function init(e:Event) : void { //called from contentloaderinfo's Event.COMPLETE
var thumb:Bitmap = e.target.content;
thumb.smoothing = true;

mainThumb = new Sprite();
mainThumb.addChild(thumb);

var overlay:Bitmap = new Bitmap(new Thumb_Overlay(0,0));
var thumbMask:Sprite = new Thumb_Mask();

mainThumb.x = overlay.x = thumbMask.x = -mainThumb.width/2;
mainThumb.mask = thumbMask;

this.addChild(mainThumb);
this.addChild(overlay);

...




i feel like this should work... but it doesn't, nothing shows up at all using this code, but when i try commenting out the masking line, and adding addChild(thumbMask),the mask shows up in the correct position

any ideas why this isn't working?

thanks a ton

edit: when i add the line, mainThumb.cacheAsBitmap = true, i see mainThumb but it is not masked...

sebrofm
May 8th, 2009, 01:35 PM
i fixed it: i just used sprite graphics to draw the png i was using from the library because i was sick of it not working, and used filters to add the effects i wanted from overlay.

Dimonte
May 8th, 2009, 01:35 PM
If I am not mistaken, you need to add a masking object as a child to the same container masked object resides in. If that won't fix the problem, the .fla would be appreciated.

sebrofm
May 8th, 2009, 01:50 PM
i'm pretty sure masks don't need to be on the display list, but i could be wrong.

Dimonte
May 8th, 2009, 02:03 PM
No, you're right, it doesn't need to be on display list, though it won't hurt, because

To ensure that masking works when the Stage is scaled, the mask display object must be in an active part of the display list.
(from the reference)

I failed to notice that you use Sprite containing the bitmap in it as a mask, not the Bitmap itself. I'm pretty sure you need to set cacheAsBitmap to true for both the mask and masked object in that case.

sebrofm
May 8th, 2009, 02:05 PM
i tried that, and then nothing showed up...oh well it doesn't really matter, the way i have it now is much cleaner anyway, i think i was just being lazy before haha.