As3 printing problem, blanks swf after print or cancel

眉间皱痕 提交于 2019-11-29 16:49:10

There are two printing types, vector and bitmap. Because you are just passing in the root it will try to print everything as a vector. But what you might be seeing is that in some versions of the Flash player on some operating systems vector printing doesn't work. I normally create a bitmap snapshot of the displayobject that you want and print this.

var bitmapData:BitmapData = new BitmapData(root.width, root.height); bitmapData.draw(root); var printThis:Bitmap = new Bitmap(bitmapData);

Make sure you add it to the stage before you print so that preview works and mind the max bitmap data size. When you are finished delete the bitmap.

To print as bitmap you can use print options as,

var printOption:PrintJobOptions = new PrintJobOptions();
printOption.printAsBitmap = true;

before addPage(...); line

But this is not the cause for blank SWF.

use following code,

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
}
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!