-1

Presently, I am attempting to add the ability to capture all the slides of a presentation to images and save them to disk. It works now where the first page is capture, then I want an async event to fire when the second page has loaded to capture that page, and so on. Here is where I have added an event listener, though I'm not sure if I should be using stage or this:

                  import flash.events.Event;
                  private var jpgEncoder:JPGEncoder;
                  // ...

                    private function init():void{
                            // ...
                            // Add async event to capture second page after loading
                            stage.loaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
                           // ...
                    }
                    private function onPrintButtonClicked():void {
                            // screen capture code
                            jpgEncoder = new JPGEncoder(90);

                            // Page 1 capture
                            bitmapData1 = new BitmapData(stage.width, stage.height);
                            bitmapData1.draw(stage, new Matrix());

                            // move to next page
                            var curPage:Page = PresentationModel.getInstance().getCurrentPage();
                            if (curPage != null) {
                                LOGGER.debug("Go to next page. Current page [{0}]", [curPage.id]);
                                pageCount++;
                                dispatchEvent(new GoToNextPageCommand(curPage.id));
                            } else {
                                LOGGER.debug("Go to next page. CanNOT find current page.");
                            }
                    }


                    private function onLoadComplete(e:Event)
                    {
                            // Get page 2 capture
                            bitmapData2 = new BitmapData(stage.width, stage.height);
                            bitmapData2.draw(stage, new Matrix());

                            // Copy two pages to one bitmap
                            var rect1:Rectangle = new Rectangle(0, 0, stage.width, stage.height);
                            var pt1:Point = new Point(0, 0);
                            bitmapData3 = new BitmapData(stage.width, stage.height * 2);
                            bitmapData3.copyPixels(bitmapData1, rect1, pt1)
                            var rect2:Rectangle = new Rectangle(0, 0, stage.width, stage.height);
                            var pt2:Point = new Point(0, stage.height);
                            bitmapData3.copyPixels(bitmapData2, rect2, pt2)

                            // Convert to image
                            var img:ByteArray = jpgEncoder.encode(bitmapData3);
                            var file:FileReference = new FileReference();
                            file.save(img, "capture1.jpg");
                    }

Does anyone have any ideas as to why the OnLoadComplete function is never called? FYI, here is the full source code: https://github.com/john1726/bigbluebutton/blob/master/bigbluebutton-client/src/org/bigbluebutton/main/views/MainToolbar.mxml

TIA

user8128167
  • 6,929
  • 6
  • 66
  • 79
  • Option 1: you don't call the **init** method. Option 2: by the time you add the listener the whole movie is already loaded and you miss the event. – Organis Jul 18 '17 at 22:16
  • Simulate mouse clicks against a button, maybe. – Vesper Jul 20 '17 at 08:12

1 Answers1

0
  1. Please note that I've found that the stage was still null in the init() method so an exception was being thrown:

    stage.loaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
    
  2. Also, after resolving that stage error I found that I have been receiving this error using this tool: https://github.com/capilkey/Vizzy-Flash-Tracer

    Error #2176: Certain actions, such as those that display a pop-up window, may only be invoked upon user interaction, for example by a mouse click or button press.

So the solution is either to re-work the UI so that there is a button press to prepare the files and a second button press to actually save the image or setup them mouseup and mousedown events to call different functions:

s:Button mouseDown="prepare_PDF()" mouseUp="save_PDF()"

Source: Flex's FileReference.save() can only be called in a user event handler -- how can I get around this?

Thank you!

user8128167
  • 6,929
  • 6
  • 66
  • 79