Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

apache flex - As3 printing problem, blanks swf after print or cancel

ok back at another issues in as3 printing

//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;
}

I cant seem to find anything thats really helpful with this. When i click cancel on the print dialog box, i get error below and it blanks out my swf.

The error consists, that whenever i try to print and cancel it, or even when i do succesfully print, swf goes blank.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...