User Guide
488 Printing
What’s new for the PrintJob class using
ActionScript 3.0
The PrintJob class hasn’t changed dramatically for the ActionScript 3.0 implementation of
printing. However, a few critical differences are worth noting:
■ The PrintJob.addPage() method now takes a Sprite and a Rectangle object for the first
two parameters.
■ ActionScript 3.0 does not support using the delete (as in delete myPrintJob) operator
to remove an entire object. In ActionScript 2.0, you could use
delete to remove an object
or an object property. In ActionScript 3.0, the
delete operator is now ECMAScript-
compatible, meaning
delete can be used only on a dynamic property of an object. The
PrintJob.start() method resets an existing PrintJob object’s properties, so you do not
need to delete any existing PrintJob objects to reuse the same variable. If you do need to
“clear” a PrintJob object’s properties for any reason, use
null (as in myPrintJob = null).
■ The global ActionScript 2.0 functions print(), printAsBitmap(),
printAsBitmapNum(), and printNum() are not supported in ActionScript 3.0. Use the
PrintJob and PrintJobOptions classes instead.
■ Because Flash Player now throws run-time exceptions for certain PrintJob.addPage()
conditions, you can write code to catch and handle the exceptions as they occur.
■ ActionScript 3.0 does not restrict a PrintJob object to a single frame (but script time-out
limits do apply, as detailed in “Timing print job statements” on page 492).
Printing a page
The ActionScript to print a basic page through Flash Player requires four major statements in
sequence:
■ new PrintJob()—Creates a new print job instance of the name you specify.
■ PrintJob.start()—Initiates the printing process for the operating system, invoking the
print dialog box for the user, and populates the read-only properties of the print job.
■ PrintJob.addPage()—Contains the details about the print job contents, including the
Sprite object (and any children it contains), the size of the print area, and whether the
printer should print the image as a vector or bitmap. You can use successive calls to
addPage() to print multiple sprites over several pages.
■ PrintJob.send()—Sends the pages to the operating system’s printer.