Search code examples
apache-flexactionscript-3flex3screenshot

Taking a screenshot of browser/tab window in flex


I'm quite new to Flex.

I've looked into taking screenshots in flex and have found many links on google and here on stackoverflow for taking screenshots of components and stuff like this. What I would like to do is take a screenshot of the entire tab in a browser window (or, failing that, the browser window itself or even just the screen).

I'm able to take a screenshot of a viewstack because it implements the IBitmapDrawable interface. But what if I want to take a screenshot of the browser tab as mentioned? Is this possible and, if so, how?

The parent of the viewstack is the application but when trying to pass Application.application to the draw method of the BitmapData class, I get the following error:

Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:IBitmapDrawable.

Thanks in advance.


Solution

  • It's not possible to take screenshots of anything that's outside of your Flex application. However, it should be possible to take a screenshot of your application. Application is a DisplayObject which implements IBitmapDrawable. The reason for your error is, that Application.application is of type Object. So, you should be able to cast your application as IBitmapDrawable and use it to get a screenshot of your application.

    // Flex 3.x
    var app:IBitmapDrawable = Application.application as IBitmapDrawable;
    
    // in Flex SDK 4.x Application.application is deprecated so use
    var app:IBitmapDrawable = FlexGlobals.topLevelApplication as IBitmapDrawable;