为什么我的动作脚本事件没有触发?

Why is my action script event not firing?

目前,我正在尝试添加将演示文稿的所有幻灯片捕获到图像并将它们保存到磁盘的功能。它现在可以在捕获第一页的地方工作,然后我希望在加载第二页以捕获该页面时触发异步事件,依此类推。这是我添加事件侦听器的地方,但我不确定我是否应该使用 stagethis:

                  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");
                    }

有人知道为什么 OnLoadComplete 函数从未被调用过吗?仅供参考,这里是完整的源代码:https://github.com/john1726/bigbluebutton/blob/master/bigbluebutton-client/src/org/bigbluebutton/main/views/MainToolbar.mxml

TIA

  1. 请注意,我发现 init() 方法中的阶段仍然为空,因此抛出了异常:

    stage.loaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
    
  2. 此外,在解决该阶段错误后,我发现我一直在使用此工具收到此错误:https://github.com/capilkey/Vizzy-Flash-Tracer

    错误 #2176:某些操作,例如显示弹出窗口的操作 window,只能在用户交互时调用,例如通过单击鼠标或按下按钮。

所以解决方案是要么重新处理 UI 以便按下一个按钮准备文件,再按下一个按钮实际保存图像,或者设置它们的 mouseup 和 mousedown 事件以调用不同的功能:

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

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

谢谢!