Taking screenshots of your stage in as3 is quite easy. For my example you just need kaourantin’s PNGEnc Class.

Download the PNGEnc class here

The guys who did the as3corelib have a PNG and JPG encoder class as well, you can download as3corelib here if you want to use their classes instead.

Here my example:

private function takeScreenshot():void 
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.utils.ByteArray;
import flash.net.FileReference;
import net.kaourantin.PNGEnc;

var bmd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0);
var bm:Bitmap = new Bitmap(bmd, "auto",true);
bmd.draw(this); // i wrote my example code in my document class, so "this" refers to my document class and the whole stage is drawn into the bitmapdata
var bild:ByteArray = PNGEnc.encode(bmd);
var file:FileReference = new FileReference();
file.save(bild, "screenshot.png");

trace("Taken Screenshot");

About Jonas

My name is Jonas Jäger and I work as a designer & developer. I recently founded my first startup comuvo.com with the wonderful Eva Bachmann. I'm a great web & technology geek, so the content on this blog will mainly focus on these topics. Since I'm also working on comuvo right now there will also be some startup-related Posts.