Monday, June 6, 2011

Printing in AS3: Part 3

In this tutorial we continue learning about printing.

We now that we can pass a PrintJobOptions object as the third parameter of the addPage() method. But when we did that last time, we left the second parameter as null. The second parameter is a rectangle object, which represents the area of our sprite that needs to be printed. If we don't want to specify a print area, we leave it null. If we want to use it though, simply create a Rectangle object with the needed settings, and apply it to the method:

var myArea:Rectangle = new Rectangle(0, 0, 600, 400);
myPrintJob.addPage(mySprite, myArea);

We can turn this into one line if we want to:

myPrintJob.addPage(mySprite, new Rectangle(0, 0, 600, 400));

Another thing that we need to know about printing in AS3 is the delay limit between instructions that we send to our PrintJob object..

Actionscript 3 doesn't limit a PrintJob object with just one frame to print, like it was limited in the previous verisons of AS. However, because the OS displays the information about the printing status to the user after they press "OK" in the print dialog window, we need to call the addPage() and send() methods as soon as possible, to send the pages to the spooler. A delay in referring to the frame results in a delay in the printing process.

Actionscript 3 has a limit for time delay - 15 seconds. Thus, time between 2 instructions we give to the PrintJob object should not be longer than 15 seconds. This means there's a 15 time limit between:

  • the PrintJob.start() and PrintJob.addPage() methods
  • the PrintJob.addPage() and the next PrintJob.addPage() methods
  • the PrintJob.addPage() and PrintJob.send() methods

If any of these delays are longer than 15 seconds, the next call of start() method returns false, and the next referring to the addPage() method for this PrintJob object makes the Flash Player ignore the request.

This is all for today's tutorial.

Thanks for reading!

Related:

Printing in AS3: Part 1
Printing in AS3: Part 2
Printing in AS3: Part 4

No comments:

Post a Comment