Avg. Rating 3.9

Problem

Let's say you want to capture the BitmapData of an instantiated control within your Flex application.

Solution

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.

Detailed explanation

First of all, it's important to understand that all Flex components within the Flex framework extend from the UIComponent class.  If you want to capture the BitmapData from any component, this is where to start.

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.

Report abuse

Related recipes