The first step involves capturing the UI component's bitmap information. The Flex 3 API introduced the ImageSnapshot class specifically to simplify this process. The following line of code is sufficient to capture the image data:
However, we are able to control the image capturing more precisely by using some of the method's optional parameters. These allow us to specify the target resolution in dots per inch and the image encoder to use (the Flex 3 API provides a PNGEncoder and a JPEGEncoder). So, for example, the following line of code would capture a chart as a PNG image at a resolution of 300dpi:
Now that we have captured the image data all that remains is the second, and last, step: saving the image data to the user's file-system. Flash Player 10 introduced a number of changes to its security sandbox, principally the ability to programmatically prompt the userto save a file to their file-system. This is done using the FileReference class, as shown in the following lines of code:
So, putting the steps together results in a method along the lines of the following code snippet:
The application below shows this code in action. The values in the data grid can be changed,with the changes reflected in the chart (just to show that I'm not cheating).
The source code is now available.