Let's say you want to capture the BitmapData of an instantiated control within your Flex application.
Below, I have provided a generic function that returns the BitmapData from any UIComponent regardless of whether or not it is visible on the screen.
First, create a generic function that takes a UIComponent as a parameter. Create a new BitmapData object, and draw the contents of the target UIComponent into the new BitmapData object. Then, return the new BitmapData object.
private function getBitmapData( target : UIComponent ) : BitmapData
{
var bd : BitmapData = new BitmapData( target.width, target.height );
var m : Matrix = new Matrix();
bd.draw( target, m );
return bd;
}
This function will work for any Flex component that extends from the following controls: UIComponent, Buttons, DataGrids, Canvases, Panels, and so forth.