BitmapData is frustrating me

Okay first off I am getting bitmapData from display objects like so


private function getDrawData(forObj : DisplayObject) : BitmapData {
    var bmpData : BitmapData = new BitmapData(forObj.width, forObj.height, true, 0);
    bmpData.draw( forObj );
    return bmpData;
}

I have this PaintedImage class, consisting of a PaintedImage, and a PaintedMask.

In this case
PaintedImage = A picture of a face
PaintedMask = BitmapData with a filled blue circle

Basically I want to apply paintedMask as a mask for PaintedImage, but nothing seems to be working. I have had both display objects using cacheAsBitmap=true.

I tried using two images, loading the data and setting one as a mask of the other but just failure. Using the default mask stuff gave me absolutely no effect. Anyone know why, or can provide me any help?

So then I tried doing this manually… i had a few ideas, such as


private function getManualMask(forImage : BitmapData, forMask : BitmapData) : BitmapData {
    var result : BitmapData = forImage;
    var rect        : Rectangle    = new Rectangle(0, 0, forImage.width, forImage.height);
   
    result.threshold( forMask, rect, new Point(0, 0), '==', drawColor, 0x00000000); 
    
    return result;
}

Above, the idea was that anything that matches the blue fill color should be set as a transparent pixel in the forImage. But that didn’t work…

I also tried this
result.copyChannel( forMask, rect, new Point(0, 0), BitmapDataChannel.ALPHA, BitmapDataChannel.ALPHA);
but that didn’t copy over the alpha transparencies for the pixels either… i guess i don’t understand how copyChannel or threshold work.

So applying a mask programatically seems to have failed me too.
Can anyone help me out here because I have no idea how to use bitmapData’s functions and apparently masks are too complicated for me

The only way I could get a mask to work was by using a sprite and having all of the data applied to it through the Graphics object. But that doesn’t work for me because some of the stuff i need to apply as a mask comes from bitmap data calculations and not just graphics drawing commands.