Creating a chroma key effect in a bitmap

hello all,
i’m trying to create a chroma key effect in a bitmap to have an irregular shape bitmap appear on any background.

my sense is that the best way to do this is with BitmapData.threshold(). chime in if there’s a better way perhaps with DisplayObject.BlendMode.ALPHA or a Bitmap filter.

the below code gets me 95% of the way there but the problem with it is that i can’t get the threshold to be just one pixel color rather than a range. so the problem with the below code is that some of the anti aliased pixels around the outside of the image don’t get keyed out since they’re close to the chroma key color. how to isolate the .threshold() to just the one chroma key color?

// code
var loadedImage:Bitmap = //load 50x50 bitmap;
var bmd_orig:BitmapData = loadedImage.bitmapData.clone();
var bmd_keyed:BitmapData = new BitmapData(50, 50, true, 0xFFCCCCCC);
var pt:Point = new Point(0, 0);
var rect:Rectangle = new Rectangle(0, 0, 50, 50);
var threshold:uint = 0x00800000;
var color:uint = 0x00FF0000;
var maskColor:uint = 0x00FF0000;
bmd_keyed.threshold(bmd_orig, rect, pt, “>”, threshold, color, maskColor, true); // operation probably should be “==” to the one pixel value
var bitmap_keyed:Bitmap = new Bitmap(bmd_keyed);
addChild(bitmap_keyed);

thx
michael