// This code assumes there is a MovieClip on stage with the instance
// name of 'pattern_mc'. Inside 'pattern_mc' there could be a mask which
// is masking all the other layers.
var bounds:Rectangle = getRealBounds(pattern_mc);
var bmpd:BitmapData = new BitmapData(bounds.width, bounds.height);
var matrix:Matrix = new Matrix();
matrix.translate(-bounds.x, -bounds.y);
bmpd.draw(pattern_mc, matrix, null, null, null, true);
var bmp:Bitmap = new Bitmap(bmpd);
bmp.x = 20;
bmp.y = 20;
addChild(bmp);
function getRealBounds(displayObject:DisplayObject):Rectangle
{
var bounds:Rectangle;
var boundsDispO:Rectangle = displayObject.getBounds( displayObject );
var bitmapData:BitmapData = new BitmapData( int( boundsDispO.width + 0.5 ), int( boundsDispO.height + 0.5 ), true, 0 );
var matrix:Matrix = new Matrix();
matrix.translate( -boundsDispO.x, -boundsDispO.y);
bitmapData.draw( displayObject, matrix, new ColorTransform( 1, 1, 1, 1, 255, -255, -255, 255 ) );
bounds = bitmapData.getColorBoundsRect( 0xFF000000, 0xFF000000 );
bounds.x += boundsDispO.x;
bounds.y += boundsDispO.y;
bitmapData.dispose();
return bounds;
}