2017-07-18 122 views
-1

目前,我正在嘗試添加將演示文稿的所有幻燈片捕獲到圖像並將其保存到磁盤的功能。它現在適用於捕獲第一頁的地方,然後我希望在加載第二頁以捕獲該頁時觸發異步事件,等等。這裏是我添加事件偵聽器,雖然我不知道我是否應該使用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

+0

選項1:您不要調用** init **方法。選項2:當您添加偵聽器時,整個電影已經加載並且您錯過了該事件。 – Organis

+0

模擬鼠標點擊一個按鈕,也許。 – Vesper

回答

0
  1. 請注意,我發現,舞臺仍然在init()方法,這樣一個異常被拋出空:

    stage.loaderInfo.addEventListener(Event.COMPLETE,onLoadComplete); 
    
  2. 此外,解決該階段錯誤後,我發現我一直在使用此工具收到此錯誤:https://github.com/capilkey/Vizzy-Flash-Tracer

    錯誤#2176:某些操作(例如顯示彈出窗口的操作)只能在用戶交互時調用,例如通過鼠標單擊或按下按鈕。

所以解決方法是,重新工作界面,因此有一個按鈕,按下準備的文件和一個第二次按下按鈕到真正保存圖像或設置他們mouseup和鼠標按下事件調用不同的功能:

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?

謝謝!

相關問題