21.9. Printing Flash Content

Problem

You want to print content from Flash.

Solution

Use the PrintJob ActionScript class.

Discussion

When you want to print Flash content, you always have the option of allowing the user to select the Print option from the Flash Player context menu. However, that is neither an obvious UI action for the user, nor does it offer much control over what will print. Instead, the better way to manage printing of Flash content is to use the PrintJob class.

The PrintJob class enables you to print one or more pages of content while prompting the user with just one dialog box. The PrintJob class enables you to print content from any frame of any movie clip, and you can even specify printable regions and how to optimize the printing depending on whether the content uses bitmaps or vectors.

The first step when working with the PrintJob class is to construct a new instance, and assign that to a variable. You can construct a new instance by using the constructor method, as in the following example:

	var pjContent:PrintJob = new PrintJob();

Next, call the start( ) method in order to prompt the user with the Print dialog box. Flash doesn’t allow you to print unless the user clicks OK from the dialog box. The start( ) method is synchronous. That means that the ActionScript interpreter halts when the start( ) method is called until the user clicks OK or Cancel from the Print dialog box. When the user clicks one of the buttons, a Boolean value is returned to Flash. If the user ...

Get Flash 8 Cookbook 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.