Flex 3 : Taking a snapshot of a component.

Even though, Flex doesn’t do printing that well, it can take a snapshot of a component.

Taking screenshots in Flex 3 using the ImageSnapshot.captureImage() method


// needed imports
import flash.net.FileReference;
import mx.graphics.codec.*;
import mx.graphics.ImageSnapshot;

// save PNG chart to user PC.
private function saveChart(source:IBitmapDrawable):void {

//var image:ImageSnapshot = ImageSnapshot.captureImage(idchartgrid, 300, new PNGEncoder());
var image:ImageSnapshot = ImageSnapshot.captureImage(source);
var file:FileReference = new FileReference();
file.save(image.data, “chart.png”);
} // end of savechart….


<mx:Panel id=”idchartgrid” width=”940″ height=”550″ title=”A9 Summary Chart”
horizontalScrollPolicy=”off” verticalScrollPolicy=”off” toolTip=”A9 Summary Chart” >

<mx:HBox id=”idIMAGE3″ >
<mx:Image source=”../../images/chart_bar.gif”
toolTip=”Create Chart” buttonMode=”true”
click=”saveChart(idchartgrid); ” />
<mx:Label text=”Create Chart” />


<mx:ColumnChart id=”mychart” dataProvider=”{chart1}”
showDataTips=”true” dataTipMode=”multiple” mouseSensitivity=”200″
height=”350″ width=”800″ >


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: