
t is no longer neccessary to creatively twist and bend Flash's printing APIs to perform the more complex printing tasks like multi-page printing. Thanks to ActionScript 2.0 and Flash Player 7, you now have direct access to a rich set of print functionality. This article explores these powerful new functions and discusses how to structure application code to take full advantage of them.

This previous article, discussing Flash Player 5, outlined a set of code strategies for printing in Flash and those techniques have aged well. Reading the previous article isn't a prerequisite, but it's not a bad idea, as this article uses the same design strategy to organize application code in a manner that makes printing even simpler and the code even more maintainable.
The PrintJob Class
The big change introduced by Flash Player 7 is the PrintJob class. PrintJob has three methods: start(), addPage(), and send() which are called during the course of printing. The standard boilerplate code looks like this:
var printJob:PrintJob = new PrintJob();
if (printJob.start()) {
var numPages:Number = 0;
if (printJob.addPage(aMovieClip)) {
numPages ++;
}
// etc.
if (numPages> 0) {
printJob.send(); // print page(s)
}
}
delete printJob;
The
numPages variable counts the pages as they are added, and ensures that at least one call to
addPage() succeeds before it calls
PrintJob.send(). In addition, the
addPage() method can take three optional parameters after the initial movie clip parameter (which is required). Those additional arguments are: a bounding box for the print area, a parameter letting Flash know whether to print as vector or bitmap, and a frame number to print. While ActionScript 2.0's documentation covers those parameters in more depth, using the techniques described below should mean that you won't have to use those additional parameters very often.
Though the actual ActionScript printing classes and methods are straightforward, how best to use them is not. The previous article outlines a technique for printing that involves copying movie clips dynamically to off-screen, pre-drawn printing interfacesinstead of printing what was on the actual user-interface. This strategy provides a much more stable and controllable printing process.