好的回到as3打印的另一个问题
//Function to print entire screen
function printFunction(event:MouseEvent):void
{
var myPrintJob:PrintJob = new PrintJob();
var oldScaleX:Number = root.scaleX;
var oldScaleY:Number = root.scaleY;
//Start the print job
myPrintJob.start();
//Figure out the new scale
var newScaleX:Number = myPrintJob.paperWidth/root.width;
var newScaleY:Number = myPrintJob.paperHeight/root.height;
//Shrink in both the X and Y directions by the same amount (keep the same ratio)
if(newScaleX < newScaleY)
newScaleY = newScaleX;
else
newScaleX = newScaleY;
root.scaleX = newScaleX;
root.scaleY = newScaleY;
//Print the page
myPrintJob.addPage(Sprite(root));
myPrintJob.send();
//Reset the scale to the old values
root.scaleX = oldScaleX;
root.scaleY = oldScaleY;
}
我似乎找不到任何对此有用的东西。当我在打印对话框上单击取消时,我得到下面的错误,它消除了我的瑞士法郎。
错误在于,无论何时我尝试打印并取消它,或者甚至在我成功打印时,swf都会变成空白。
答案 0 :(得分:0)
有两种打印类型,矢量和位图。因为你只是传入根目录,它将尝试将所有内容打印为矢量。但是您可能会看到,在某些操作系统上的某些版本的Flash播放器中,矢量打印不起作用。我通常会创建所需的displayobject的位图快照并打印出来。
var bitmapData:BitmapData = new BitmapData(root.width, root.height);
bitmapData.draw(root);
var printThis:Bitmap = new Bitmap(bitmapData);
确保在打印之前将其添加到舞台上,以便预览工作并注意最大位图数据大小。完成后删除位图。
答案 1 :(得分:0)
要打印为位图,您可以使用打印选项,
var printOption:PrintJobOptions = new PrintJobOptions();
printOption.printAsBitmap = true;
在addPage(...)之前;线
但这不是空白SWF的原因。
使用以下代码,
function firePrint(e:MouseEvent):void
{
printImage(Img);
}
printBtn.addEventListener(MouseEvent.CLICK, firePrint, false, 0, true);
function printImage(mc:MovieClip):void
{
var realW:Number = mc.width;
var realH:Number = mc.height;
var orgX:Number = mc.x;
var orgY:Number = mc.y;
var pj:PrintJob = new PrintJob();
var pageCount:Number = 0;
var printOption:PrintJobOptions = new PrintJobOptions();
printOption.printAsBitmap = true;
if (pj.start())
{
mc.x = 0;
mc.y = 0;
var cXscale:Number,cYscale:Number;
if (pj.orientation.toLowerCase() != "landscape")
{
mc.rotation = 90;
mc.x = mc.width;
cXscale = (pj.pageWidth / realH) * 100;
cYscale = (pj.pageHeight / realW) * 100;
}
else
{
cXscale = (pj.pageWidth / realW) * 100;
cYscale = (pj.pageHeight / realH) * 100;
}
mc.scaleX = mc.scaleY = Math.min(cXscale,cYscale);
if (pj.addPage(mc,new Rectangle(0,0,realW,realH)))
{
pageCount++;
}
if (pageCount > 0)
{
pj.send();
}
mc.scaleX = mc.scaleY = 100;
mc.rotation = 0;
mc.x = orgX;
mc.y = orgY;
pj = null;
}else
{
//No printer or prnting is cancelled
}
}