ADOBE FLEX 3
Developer Guide
512
Timing print job statements
ActionScript 3.0 does not restrict a PrintJob object to a single frame (as did previous versions of ActionScript).
However, because the operating system displays print status information to the user once the user has clicked the OK
button in the Print dialog box, you should call
PrintJob.addPage() and PrintJob.send() as soon as possible to
send pages to the spooler. A delay reaching the frame containing the
PrintJob.send() call will delay the printing
process.
In ActionScript 3.0, there is a script time-out limit of 15 seconds. Therefore, the time between each major statement
in a print job sequence cannot exceed 15 seconds. In other words, the 15-second script time-out limit applies to the
following intervals:
Between PrintJob.start() and the first PrintJob.addPage()
Between PrintJob.addPage() and the next PrintJob.addPage()
Between the last PrintJob.addPage() and PrintJob.send()
If any of these intervals spans more than 15 seconds, the next call to
PrintJob.start() on the PrintJob instance
returns
false, and the next PrintJob.addPage() on the PrintJob instance causes Flash Player or AIR to throw a
run-time exception.
Setting size, scale, and orientation
The section “Printing a page” on page 509 details the steps for a basic print job, where the output directly reflects the
printed equivalent of the screen size and position of the specified sprite. However, printers use different resolutions
for printing, and can have settings that adversely affect the appearance of the printed sprite.
Flash Player and AIR can read an operating systems printing settings, but note that these properties are read-only:
although you can respond to their values, you can’t set them. So, for example, you can find out the printer’s page size
setting and adjust your content to fit the size. You can also determine a printer’s margin settings and page orientation.
To respond to the printer settings, you may need to specify a print area, adjust for the difference between a screens
resolution and a printers point measurements, or transform your content to meet the size or orientation settings of
the users printer.
Using rectangles for the print area
The PrintJob.addPage() method allows you to specify the region of a sprite that you want printed. The second
parameter,
printArea, is in the form of a Rectangle object. You have three options for providing a value for this
parameter:
Create a Rectangle object with specific properties and then use that rectangle in the addPage() call, as in the
following example:
private var rect1:Rectangle = new Rectangle(0, 0, 400, 200);
myPrintJob.addPage(sheet, rect1);
If you havent already specified a Rectangle object, you can do it within the call itself, as in the following example:
myPrintJob.addPage(sheet, new Rectangle(0, 0, 100, 100));
If you plan to provide values for the third parameter in the addPage() call, but dont want to specify a rectangle,
you can use
null for the second parameter, as in the following;
myPrintJob.addPage(sheet, null, options);

Get ADOBE® FLEX® 3: PROGRAMMING ACTIONSCRIPT™ 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.