// GRAYSCALE AND IMAGE snippet
// "Bit" is the linkage ID of the bitmap in the Library
var colorMC : Sprite = new Bit();
// sendToGray takes 3 parameters width, height, and Sprite
addChild( sendToGray( 306, 176, colorMC ));
function sendToGray( w:int, h:int, drawItem:Sprite ) : Bitmap
{
var myBitmapData : BitmapData = new BitmapData( w, h );
myBitmapData.draw( drawItem );
var bmp : Bitmap = new Bitmap( setGrayScale(myBitmapData) );
return bmp;
}
function setGrayScale( obj:BitmapData ) : BitmapData
{
var rLum : Number = 0.2225;
var gLum : Number = 0.7169;
var bLum : Number = 0.0606;
var matrix:Array = [ rLum, gLum, bLum, 0, 0,
rLum, gLum, bLum, 0, 0,
rLum, gLum, bLum, 0, 0,
0, 0, 0, 1, 0 ];
var filter:ColorMatrixFilter = new ColorMatrixFilter( matrix );
obj.applyFilter( obj, new Rectangle( 0,0,obj.width,obj.height ), new Point(0,0), filter );
return obj;
}