How do you capture some part of, or entire stage (much like a screenshot) and export it as a PNG image.
I have written a class that I would like to share here which lets you export images from Flash to PNG (via PHP).
Author:
Muhammad bin Yusrat
Description: Make it easy to export PNG/JPG Images from with in Flash. You can take a snapshot of any MovieClip (or the entire stage) and tell the class to export it to PHP which then saves it on the server. The usage of the script will require only two lines for the basic export
of image.
Functions:
This function accepts two arguments. One is the target MovieClip that needs to be snapped. Second is an optional Rectangle (flash.geom.Rectangle) which, if passed, will crop the image to that rectangle.
Once the movieclip has been snapped you can simply call this second function and give it the URL to the PHP Page (or any other server side language, sample PHP included in the files) and it will send the image to it. Basically it encodes the image to Base64 which can easily be decoded using
PHP, ASP or any other language without having to install any specific component on the server. This
DOES NOT require GD Library with PHP. If you do not know what I am saying, don't worry.. just read on..
The function has 1 primary and 3 optional arguments.
1.
PageURL: The data will be sent to this page. Pass it as a string. Required.
2.
onComplete: A function to be invoked once the image has been send successfully. Optional.
3.
ProgressFunction: In case you need to show the user some progress of how much image has been uploaded, this parameter can be used. It passes a ProgressEvent to the function. Optional.
4.
vars: Just in case you need to send some additional POST variables (Session IDs, etc..) to the receiving page, you can use this parameter. See below examples. This is also optional.
Here is the easiest way to export PNG image with ActionScript 3 using this class:
import com.muhammadbinyusrat.PNGExport;
var exporter:PNGExport = new PNGExport();
exporter.Snap(testClip);
exporter.SendTo("getImage.php");
+