Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 为什么我的动作脚本事件没有触发?_Actionscript 3_Flash_Apache Flex_Actionscript - Fatal编程技术网

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

Actionscript 3 为什么我的动作脚本事件没有触发?,actionscript-3,flash,apache-flex,actionscript,Actionscript 3,Flash,Apache Flex,Actionscript,目前,我正在尝试添加将演示文稿的所有幻灯片捕获到图像并保存到磁盘的功能。现在它可以在第一个页面被捕获的地方工作,然后我希望在第二个页面被加载以捕获该页面时触发一个异步事件,依此类推。这里是我添加事件侦听器的地方,尽管我不确定是应该使用stage还是this: import flash.events.Event; private var jpgEncoder:JPGEncoder; // .

目前,我正在尝试添加将演示文稿的所有幻灯片捕获到图像并保存到磁盘的功能。现在它可以在第一个页面被捕获的地方工作,然后我希望在第二个页面被加载以捕获该页面时触发一个异步事件,依此类推。这里是我添加事件侦听器的地方,尽管我不确定是应该使用
stage
还是
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");
                    }
有人知道为什么从不调用
onload complete
函数吗?仅供参考,以下是完整的源代码:

短暂性脑缺血发作

  • 请注意,我发现
    init()
    方法中的stage仍然为null,因此引发了异常:

    stage.loaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
    
  • 此外,在解决该阶段错误后,我发现我一直在使用此工具接收此错误:

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

  • 因此,解决方案是重新处理UI,以便按下按钮准备文件,然后按下第二个按钮实际保存图像,或者设置它们mouseup和mousedown事件以调用不同的函数:

    s:Button mouseDown="prepare_PDF()" mouseUp="save_PDF()"
    
    资料来源:


    谢谢大家!

    选项1:不调用init方法。选项2:当你添加监听器时,整个电影已经被加载,你错过了这个事件。也许可以模拟鼠标点击一个按钮。