[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Screen Capture with ActionScript

Published on
13,402 Points
4 Endorsements
Last Modified:
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which helped me to develop a component for screen capture, and thought I would share my experience (and code) with you.

With a hope that this will appeal and help someone else out there, I have posted it here:

The Solution :

Below is the Main mxml page developed using Adobe Flash Builder, SDK 4.1, Flash Player version 10.1.0. In this example I am doing a screen capture of the stage.
I have added a video and placed 3 buttons, Record, Stop and Play.
On clicking on the Record button, the recording of the page starts. Once you click on stop, it stops recording.
Then click on Play button to see the recorded version. You may have other things/animations on stage for recording too, I have just tried with an flv.
The recording play is basically bytesArray of an FLV created on run-time. You can save it to your server by passing this binary data to any back-end technology - ASP.Net or PHP, etc.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
width="955" height="600"
frameRate="24" >

             import com.dd.screencapture.ScreenCapture;
             import com.dd.screencapture.SimpleFlvWriter;

             private var screenCapture:ScreenCapture;

             private function onInit():void
                  screenCapture = ScreenCapture.getInstance();
                  screenCapture.source = stage;
                  screenCapture.fps = 12;
                  screenCapture.size( 400, 300 );
                  screenCapture.x = 400;
                  screenCapture.y = 250;
                  stage.addChild( screenCapture );

             private function startRecord( event:MouseEvent ):void

             private function stopRecord( event:MouseEvent ):void

             private function playVideo( event:MouseEvent ):void
   <s:VideoDisplay width="400" height="300" source="assets/myVideo.flv" />

   <mx:HBox >
       <s:Button label="Record" click="startRecord( event );" />
       <s:Button label="Stop" click="stopRecord( event );" />
       <s:Button label="Play" click="playVideo( event );" />

Open in new window

Place the ScreenCapture.swc in lib folder of the flex project. You may also use this swc for any ActionScript 3.0 projects. Kindly note that this requires Flash Player 10.1 to run properly.

Note: The below ScreenCapture.swc has been renamed to ScreenCapture.swc.txt for security reasons (so remember to remove the .txt extension when you save it). SWC is a Shockwave Flash component file. A SWC file is a zip-like file (packaged and expanded by means of the PKZIP archive format) generated by the Flash authoring tool.

Interestingly, you can save the screen capture as FLV format by using this piece of code below:
var saveFile:FileReference = new FileReference();
saveFile.save( screenCapture.data, "video.flv" );//screenCapture is the ScreenCapture instance created in the above code block.

Open in new window

Resources used: http://www.zeropointnine.com/blog/simpleflvwriteras-as3-class-to-create-flvs/
The links shows how to save BitmapData to an FLV in binary format and then save to dish using Adobe AIR, using FileStream. I have taken the part of writing the binary data for FLV and playing that FLV as stream on run-time.

This has been published at http://deepanjandas.wordpress.com/2011/02/05/screen-capture-with-actionscript/
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Join & Write a Comment

Suggested Articles

In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month