AS3 - PrintJob - 打印阶段或阶段的一部分

时间:2013-06-23 15:41:21

标签: actionscript-3 printing

我无法打印舞台:

btn.addEventListener(MouseEvent.CLICK, printFunction);

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

}

它给我一个编译错误:

1118:使用静态类型flash.display隐式强制值:显示对象可能不相关的类型flash.display:Sprite。

我也试过了:

myPrintJob.addPage(Sprite(0));

没有编译错误;但是当我单击打印按钮时,没有打印对话框,Flash中的输出部分给出了这个错误:

TypeError:错误#1034:类型强制失败:无法将0转换为flash.display.Sprite。     在Untitled_fla :: MainTimeline / printFunction()

1 个答案:

答案 0 :(得分: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 );
相关问题