Skip navigation
MTL_SHAF
Currently Being Moderated

ImageSnapshot and Popup Windows

Oct 26, 2009 1:49 PM

Hi, I have an application that has several windows that were created using the PopUpManager. I would like the user to be able to take a screenshot of the the app so I am using the ImageSnapshot class.

 

The application is being captured but none of the pop up windows are showing up. Is there any way I can achieve this?

 

I have attached an example of the problem. You will need to ensure that the project is set to require Flash Player Version 10.0 in the flex compiler options.

 

To see the problem click on 'Pop up box' then click on 'Capture Image'

 

Thanks in advance

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
   
    <mx:Script>
        <![CDATA[
            import mx.graphics.codec.PNGEncoder;
            import mx.graphics.ImageSnapshot;
            import mx.managers.PopUpManager;
            import mx.containers.TitleWindow;
            import flash.net.FileReference;
           
            private var titleWindow : TitleWindow;
           
            private function captureImage() : void{
               
               var sn : ImageSnapshot;
               sn = ImageSnapshot.captureImage(form,100,new PNGEncoder());
                var file:FileReference = new FileReference();
               file.save(sn.data, "captured.png");
                          
            }
           
            private function showPopUp() : void {
               
                if (titleWindow == null)
                {
                    titleWindow = TitleWindow(PopUpManager.createPopUp(this.form,TitleWindow,false));
                    titleWindow.height = 115;
                    titleWindow.width = this.form.width / 2;
                    titleWindow.title = "My title window " + new Date();
                    PopUpManager.centerPopUp(titleWindow);
                   
                }
                else
                {
                    PopUpManager.removePopUp(titleWindow);
                    titleWindow = null;
                }
            }
           
           
        ]]>
    </mx:Script>
   
   
    <mx:VBox id="form">
        <mx:Button label="Capture Image" click="captureImage();" />
        <mx:TextArea id="txtBox" width="800" height="600"    />
        <mx:HRule/>
        <mx:Button label="Pop up box" click="showPopUp();" />
               
    </mx:VBox>
   
   
   
</mx:Application>

 
Replies
  • Currently Being Moderated
    Feb 8, 2014 9:36 AM   in reply to MTL_SHAF

    late response but...

    The problem is that PopupManager "creates new top-level windows and places or removes those windows from the layer on top of all other visible windows", which means Popup is not a child of Application.

    The SystemManager "parents all displayable things within the application like the main mx.core.Application instance and all popups, tooltips, cursors, and so on", so to capture BitmapData you need to reference object which contains popup and Application instance.

     

    Im not sure if this is preferable way to do it, but to get snapshot of everything visible ond screen you can use SystemManagers "getSWFRoot" method as in ImageSnapshot.captureBitmapData(SystemManager.getSWFRoot(this));

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points