Image.ScreenCapture.toJpgAsync() This page was last modified over 30 day(s) ago and has 0 comment(s)


Back to Image.ScreenCapture Class Summary

Availability
Windows, Mac OSX

Usage
mdm.Image.ScreenCapture.toJpgAsync(x:Number, y:Number, width:Number, height:Number, filePath:Number):Void

Parameters
x:Number - X coordinate of area to be captured
y:Number - Y coordinate of area to be captured
width:Number - Width of area to be captured in pixels
height:Number - Height of area to be captured in pixels
filePath:String - Location of JPG file to be created

Returns
Nothing

Description
Saves a JPG snapshot of the defined desktop area. This is asynchronous method so to be able to know when method completes you would need to assign event listeners for "onComplete" and/or "onIOError" type of events to mdm.Image.ScreenCapture (see below sample code)

Notes
None

Example Code
// there are two types of events
// that we could listen in mdm.Image.ScreenCapture object
const COMPLETE:String = "onComplete";
const IO_ERROR:String = "onIOError";
// the variable that will contain a path of bitmap to be created
var path:String = null;
//
// on button click make screen shot
//
function buttonClickHandler(event:MouseEvent):void
{
// add event handlers to mdm.Image.ScreenCapture
mdm.Image.ScreenCapture.addEventListener(COMPLETE, onCompleteHandler);
mdm.Image.ScreenCapture.addEventListener(IO_ERROR, onIOErrorHandler);
// compute path and assign it to variable for later use
path = mdm.Application.path+"ScreenCaptureToJpgAsync.jpg";
// captureRect is flash.geom.Rectangle instance that holds information
// about size and location of area to be captured
mdm.Image.ScreenCapture.toJpgAsync(captureRect.x,
captureRect.y,
captureRect.width,
captureRect.height,
path);
}
//
function onCompleteHandler(event:Event):void
{
// remove listeners
mdm.Image.ScreenCapture.removeEventListener(COMPLETE, onCompleteHandler);
mdm.Image.ScreenCapture.removeEventListener(IO_ERROR, onIOErrorHandler);
// we should get file at path being created by screen capture
var exists:Boolean = mdm.FileSystem.fileExists(path);
if(exists)
{
if(path.indexOf(" ") > 0) path = "\""+path+"\"";
mdm.MacShell.exec("open "+path);
} else
{
// file does not exists for some reason
throw new Error("Failed to capture file at path: "+path);
}
}
//
function onIOErrorHandler(event:Event):void
{
// remove listeners
mdm.Image.ScreenCapture.removeEventListener(COMPLETE, onCompleteHandler);
mdm.Image.ScreenCapture.removeEventListener(IO_ERROR, onIOErrorHandler);
// let error to be handled by global uncaugh error handler here
throw new Error("Failed to capture screen to file at path: "+path);
}

mdm.Image.ScreenCapture Class Example Downloads
No Example Downloads Available


Registered Users must be logged in to 'MyAccount' to add a Comment - Log In Here
  After Logging In, Click Here to Refresh This Page