Currently it is not posssible to create a screen capture application using AS 3.0 and AIR Beta 1.

I built a demo screen capture application to test the fact.

Here is the screenshot of the application:

Image created and saved by the application:


Here is the code of the application I built to test the fact.

//code begin//
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”; layout=”absolute” applicationComplete=”init();”>
background-color: “”;
background-image: “”;
margin-top: 0;
margin-right: 0;
margin-bottom: 0;
margin-left: 0;


import mx.controls.Alert;

import flash.display.Bitmap;
import com.adobe.images.JPGEncoder;
import flash.filesystem.*;

private var bitmapData:BitmapData;
private var newImage:File;
private var fileStream:FileStream;

private function init():void {
fileStream = new FileStream();
stage.window.width = 500;
stage.window.height = 500;

private function snagPic():void {
bitmapData = new BitmapData(this.width,this.height,false,0x00000000);
bitmapData.draw(this,new Matrix());
var bitmap : Bitmap = new Bitmap(bitmapData);
var jpg:JPGEncoder = new JPGEncoder();
var ba:ByteArray = jpg.encode(bitmapData);
newImage = File.applicationStorageDirectory.resolve(“Images/” + fileName.text + “.jpg”);
fileStream = new FileStream();, FileMode.UPDATE);
private function onClose(evt:MouseEvent):void

<mx:Panel x=”50″ y=”37″ width=”250″ height=”200″ layout=”absolute”>
<mx:TextInput x=”35″ y=”87″ id=”fileName” text=”MyNewFile”/>
<mx:Button x=”83″ y=”284″ label=”snap” click=”snagPic()”/>
<mx:Button x=”207.5″ y=”284″ label=”Close” click=”onClose(event)”/>


//code ends//

Note : Make the application transparent.

The application tries to save the image of the stage along with all the display object on it in the runtime.The stage is set to while running the application we only see the display objects and not the stage.

But when the image is drawn on a BitmapData object the background color is set to white when transparent property is set to true in case of the property being set to false, the background color turns black.

Colin Moock also discussed about screen captures in Essential Actionscript 3.0 book. Here is an excerpt from the book: No arbitrary screen captures
Note that it is not possible to take a screen capture of an arbitrary rectangular region of the
screen via ActionScript. ActionScript can only copy display objects to bitmap format.
ActionScript’s closest analog to screen capturing the display area is to use the Stage instance
as draw()’s source parameter, as in:
var canvas:BitmapData = new BitmapData(100, 100, false, 0xFFFFFFFF);
where someDisplayObject is a DisplayObject instance on the display list. The preceding
code will produce a bitmap containing every object currently on the display list, with the
following caveats:
• The .swf file’s background color is not copied to the bitmap.
• If any objects on the display list are inaccessible due to security restrictions, they are not copied to the bitmap and a SecurityError exception is thrown.”

Lets hope that building such an application will be possible the release of AIR version 1.