I'm still working on my window cleaning game from one of my previous questions

I marked a contribution as my answer, but after all this time I can't get it to work and I have to many questions about this so I decided to ask some more about it. As a sequel on my mentioned previous question, my question to you is:

How can I check whether or not a bitmapData contains non transparent pixels? Subquestion: Is this possible when the masked image is a movieclip? Shouldn't I use graphics instead?

Information I have: A dirtywindow movieclip on the bottom layer and a clean window movieclip on layer 2(mc1) on the layer above.

To hide the top layer(the dirty window) I assign a mask to it.


// this creates a mask that hides the movieclip on top
var mask_mc:MovieClip = new MovieClip();

//assign the mask to the movieclip it should 'cover'
mc1.mask = mask_mc;

With a brush(cursor) the player wipes of the dirt ( actualy setting the fill from the mask to transparent so the clean window appears)

//add event listeners for the 'brush'

//function to drag the brush over the mask
function brushDown(dragging:MouseEvent):void{
    MovieClip(dragging.currentTarget).addEventListener(Event.ENTER_FRAME,erase) ;

//function to stop dragging the brush over the mask
function brushUp(dragging:MouseEvent):void{

//fill the mask with transparant pixels so the movieclip turns visible
function erase(e:Event):void{

  • \$\begingroup\$ Since your question is already tagged with actionscript-3, you don't need to also dump the tag in your question's title - I've edited it out. \$\endgroup\$ Nov 7 '12 at 13:48

You're not working with bitmaps here. The graphics object you're using uses vector graphics. So basically you're painting a lot of rectangles to your mask...

The only reasonable way to determine whether or not your mask is entirely filled would be to render it to a BitmapData (using BitmapData.draw) and then iterate through the pixels until you hit a transparent one. In that case your mask still contains transparent parts. If you checked all pixels without hitting a transparent pixel, your mask is completely filled.

This seems overly complicated though. I'd work on a Bitmap right from the start (eg. your "dirty" layer is a bitmap on top of your clean MovieClip. Then you actually erase the dirty pixels instead of using a mask.

Update: I did a quick test of the Bitmap based approach. Here's the result (there's an indicator circle that always jumps to the first non-transparent pixel. Otherwise it would be too difficult to find all the pixels). And here's the source-code.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.