2013-06-23 97 views
1

我不能打印階段:AS3 - PrintJob的 - 印刷階段或階段的一部分

btn.addEventListener(MouseEvent.CLICK, printFunction); 

function printFunction(event:MouseEvent):void 
{ 
    var myPrintJob:PrintJob = new PrintJob(); 
    myPrintJob.addPage(0); 
    myPrintJob.send(); 

} 

它給了我一個編譯錯誤:

1118:靜態類型flash.display使用的值隱式強制:DisplayObject與可能無關的類型flash.display:Sprite。

我也試過:

myPrintJob.addPage(Sprite(0)); 

沒有編譯錯誤;但是當我單擊打印按鈕時,沒有打印對話框,並且Flash中的輸出部分給我出現此錯誤:

TypeError:錯誤#1034:類型強制失敗:無法將0轉換爲flash.display.Sprite。 at Untitled_fla :: MainTimeline/printFunction()

+0

這不是您的問題。如何聲明'btn'? – Dave

回答

3

Printjob's addPage method期待Sprite作爲第一個參數。

你想通過傳遞0來達到目的?

如果你想有一個空白頁,請嘗試:

var myPrintJob:PrintJob = new PrintJob(); 
myPrintJob.start(); /*Initiates the printing process for the operating system, calling the print dialog box for the user, and populates the read-only properties of the print job.*/ 
myPrintJob.addPage(new Sprite()); 
myPrintJob.send(); 

有一個紅色的方形又如:

var s:Sprite = new Sprite(); 
s.graphics.beginFill(0xFF0000); 
s.graphics.drawRect(0, 0, 80, 80); 
s.graphics.endFill(); 

var myPrintJob:PrintJob = new PrintJob(); 
myPrintJob.start(); /*Initiates the printing process for the operating system, calling the print dialog box for the user, and populates the read-only properties of the print job.*/ 
myPrintJob.addPage(s); 
myPrintJob.send(); 

更多信息here

要打印階段的一部分,你可以:

1)總結要在精靈打印和精靈通過對addPage(一切)。

2)使用的BitmapData

var bd :BitmapData = new BitmapData(stage.width, stage.height, false); 
bd.draw(stage); 
var b:Bitmap = new Bitmap (bd); 
var s:Sprite = new Sprite(); 
s.addChild(b); 

var printArea = new Rectangle(0, 0, 200, 200); // The area you want to crop 

myPrintJob.addPage(s, printArea); 
+1

@Milad Ghattavi,文檔還說,在調用'addPage()'一次或多次後,您需要調用start()或start2()方法來開始打印... –

+0

@Sunil D,謝謝你指出,你是對的,start()調用失蹤。 –

+0

@ san.chez我正在嘗試打印舞臺的一部分。 – Milad