Flash Action Script 3: Converting MovieClip As Images – Jpg Or Png
October 10, 2010

In order to create images, you need to access the pixel data of the MovieClip object. The data can be obtained by rendering a MovieClip into a BitmapData object and using this data, you can write your own encoder to convert it to any image format you’d like. Writing such encoder is not a trivial task and requires understanding of the image format algorithm, or you can use pre-written libraries.
You can download the PNGEncoder and JPGEncoder , which is part of as3corelib, an open source project library from:


The library allows you to convert MovieClip to either JPG or PNG format, which you can then use to send into external script for saving or uploading. An example is shown below:

	import com.adobe.images.JPGEncoder;

	var bitmapData:BitmapData=new BitmapData(mc_canvas.width, mc_canvas.height);
	var jpgEncoder:JPGEncoder = new JPGEncoder(90);
	var byteArray:ByteArray = jpgEncoder.encode(bitmapData);

	byteArray = PNGEncoder.encode(bitmapData);

In the example, mc_canvas if your MovieClip and the byteArray is the bitmap data which in this example is encoded in JPG format (the process is very similar with PNG). You can then send this data to external script, such as PHP to save it as a JPG file.


You can check a working example and source code here: