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=”http://www.adobe.com/2006/mxml” layout=”absolute” applicationComplete=”init();”>
<mx:Style>
Application
{
background-color: “”;
background-image: “”;
margin-top: 0;
margin-right: 0;
margin-bottom: 0;
margin-left: 0;
}
</mx:Style>
<mx:Script>
<![CDATA[
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();
fileStream.open(newImage, FileMode.UPDATE);
fileStream.writeBytes(ba);
}
private function onClose(evt:MouseEvent):void
{
stage.window.close();
}
]]>
</mx:Script>
<mx:Panel x=”50″ y=”37″ width=”250″ height=”200″ layout=”absolute”>
<mx:TextInput x=”35″ y=”87″ id=”fileName” text=”MyNewFile”/>
</mx:Panel>
<mx:Button x=”83″ y=”284″ label=”snap” click=”snagPic()”/>
<mx:Button x=”207.5″ y=”284″ label=”Close” click=”onClose(event)”/>
</mx:Application>
//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 transparent.so 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:
“26.7.1.2. 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);
canvas.draw(someDisplayObject.stage);
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.
16 comments
Comments feed for this article
September 1, 2007 at 2:33 pm
Mike Huntington
In my honest opinion .. a screen capture of my entire desktop could be dangerous… especially if put into the wrong hands. Screen shots could be taken and uploaded to some server… who knows… I understand if someone wants to capture screenshots of ONLY their application…. I have no problem with that. And you can currently do that with AIR. (I don’t really see why an application would need my a capture of my ENTIRE desktop anyway..)
September 1, 2007 at 3:31 pm
Ash
I dunno if this will ever be possible for security reasons. An app could capture images of the desktop and upload them somewhere without the users permission. Anything thats bad for security is bad for AIR 🙂
September 1, 2007 at 3:41 pm
John Dowdell
Am I understanding your post correctly? You’d like to use ActionScript to capture the contents of the audience’s desktop, which could then (possibly) be sent back to your server without their knowledge. Is that the type of situation you’re trying to achieve?
jd/adobe
September 2, 2007 at 5:04 am
flnotes
My requirements are simple.
I wanted to capture and save the screenshot of my own AIR application with its system chrome set to transparent (as you can see the screenshot of application while running). But the output generated shows a white background replaced for the transparent background of the application. So the application does not meet its requirements.
Now everyone has got this opinion of security issues, which I think is a valid one.But we all know that crippling the capabilities or introducing constraints to framworks or environments to prevent some misuse always works until a third party solution is introduced.
Just think of accessing the user’s computer from flash player before AIR framework came into picture. Macromedia advocated it should not be allowed for security reasons. But use some third party solutions and you can override security restrictions.
I would request everyone to consider the following scenarios before jumping to any conclusions regarding security issues.
1) An online learning application where the learners can view what the instructor is doing on the screen in real time.
2) A pixel-measurement widget which is used to measure pixel distance between two points on the screen and allows the user to take a screenshot for comparision later on.
In the first case screenshot data is sent to server,while in the second case the data is saved on the user’s computer. Hence there may be security concern in the first case but there is none in the second case.
And because Adobe wants to prevent us from building the first kind of application for security reasons, we are not able to create the second type of application.
This means either we look somewhere else for the solution or Adobe enables us to do it.
September 3, 2007 at 3:56 am
John Dowdell
… so does that mean my summary was correct, and you’re trying to capture the user’s desktop in your SWF…?
… possibly with a new type of sandbox which does not transmit (at least in a raw way) that data to the server?
(If so, then it doesn’t matter to what beneficial use you’d like to put such an ability, because other people would abuse such an ability.)
jd/adobe
September 3, 2007 at 9:15 am
flnotes
It is true that we cannot predict how people would use or abuse an application. But we can always put some kind of sandbox security around it to prevent some sort of common abuses.
If this sort of thing is possible, then I think crippling an environment with unnecessary restrictions is just too much. It is like cutting off the head to prevent headache.
September 3, 2007 at 10:18 am
Kelvin Luck
I asked a similar question to an Adobe employee at an event as was told that this would be possible. I bought up the security issue and he basically said “people have chosen to run an executable file – they need to be aware of the dangers of doing this”. I was a bit surprised because obviously a malicious app written in AIR would reflect badly on AIR itself but he was firmly of the opinion that AIR would be powerful enough to write apps (useful or malicious) and that users should only install AIR apps that they trusted. This sounds different to what JD is saying above so not sure if Adobe have changed their mind on it in the last month or so…
September 5, 2007 at 2:05 pm
Ian
My only issue with screen caps is that on OSX, they don’t currently work quite right when using SHIFT+APPLE+4-SPACE to capture only the app window… transparency is lost.
I too would be concerned security wise if every air app could take screen caps, although I can see some usefull functionality in it as well.
September 7, 2007 at 11:17 am
flnotes
I think we can create screen capture app using mdm Zinc V2.5 (http://www.multidmedia.com/software/zinc/). It now supports AS 3 and Flex2.
You can also download a sample file named Simple Mac OSX Image Capture (Exchange File#000123) from mdm file exchange page.
Here is the full url (http://www.multidmedia.com/support/developers/exchange/?action=show&id=123)
Does it mean applications developed using Zinc are not secure enough ?
And yes they are also coming up with something called Pandora.
From the FAQs page..
Adobe Systems unveiled their Adobe Integrated Runtime (AIR), formerly known as “Apollo”, just a few weeks ago and MDM feel now is the right time to announce the development of Pandora. According to the official Pandora Page, “Pandora was conceived prior to any announcements about Apollo. However, given the timing and the nature of both products, comparisons with Adobe Apollo/AIR are to be expected.”
Adobe better take notice.
October 2, 2007 at 8:37 pm
laduch
I have question…
What kind of database work best for AS3??
I like MySQL… but I don’t know anything about AS3 yet.
October 20, 2007 at 2:23 pm
nalnalital
ridiculous, if I can erase my HD, write files, and more, why can’t take snapshot of my desktop ^^
I’m very desapointed to use zinc, that’s a good product, I used it many times since 2001, but I prefer the Adobe syntax, you see the result just by compiling in AIR, when you need to export by zinc…
February 14, 2008 at 3:19 am
David McArdle
No joke, sharing a desktop is not a bad feature. I can allow access to my web cam. What is different about a desktop. If my web cam was pointed at my desktop, Adobe will still give my swf access to the web cam (with the user’s permission of course). Please Adobe, let me build a screen cast client that does not require an operating system specific driver or java. Not that java is bad, I just like it for my server.
March 20, 2008 at 4:06 pm
Noel B
I think this would be a great feature for AIR.
The security concerns are way off base. Adobe Air already has file system access, meaning that it can already open, copy, and send a large variety of local data surrepticiously to a foreign server (as can pretty much any application you download and run locally).
Sending a screenshot of your desktop seems quaint in comparison.
April 16, 2008 at 6:26 pm
dede
Does anyone know when would AIR go to final release?
August 12, 2008 at 8:49 pm
Muhammad Hassan
I believe Adobe should add this feature, the application already have file access, and it can call another native (or java) application (see http://blog.everythingflex.com/2008/04/24/do-a-screen-capture-with-adobe-air/) to do that work for it and Adobe – Captivate do this, see http://www.adobe.com/products/captivate/
So what is the problem?
I hope Adobe add that feature soon
May 10, 2011 at 2:18 pm
Andrew Westberg
http://simplifiedlogic.com/nitroscreencap