Bitmapdata.threshold for automatic background removal

Ok peeps so i have simple task to preform and one that i’m sure you uber coders will be able to help with.

Basically, i want to import an image externally, load it into a bitmap object, grab the colour of the top right most pixel then copy the image into another bitmap object (or itself) and set that colour to fully transparent. This bitmapdata is in a movieclip with a shadow filter on it.

In a nutshell its an automatic background removal script.

I have had limited success with the threshold command. I can pick the colour i want and change it to a degree. I have also got this background colour to go fully transparent to show whatever movieclip is underneath, but I can only do this when the pixels i want to keep go black :O(

So this left me to think that maybe i can use the threshold to figure out what pixels need to be transparent, make a black and white alpha mask then apply that to a copy of the original - so that the background pixels are true transparent and show the movieclips behind.

Failing that, i guess after working out which pixels need to be transparent it can save them all to a array then go through all the pixels of the bitmapdata one at a time and delete the pixels. It only needs to do it once so if its a little slow its not the end of the world.

Does that make sense?