13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Printing<br />

If the Flash runtime <strong>en</strong>counters a problem s<strong>en</strong>ding the print job to the printer (for example, if the printer is offline),<br />

you can catch that exception, too, and provide more information or more options (such as displaying message text or<br />

providing an alert within an animation). For example, you can assign new text to a text field in an if..else statem<strong>en</strong>t,<br />

as the following code shows:<br />

if (myPrintJob.start())<br />

{<br />

try<br />

{<br />

myPrintJob.addPage([params]);<br />

}<br />

catch (error:Error)<br />

{<br />

// Handle error.<br />

}<br />

myPrintJob.s<strong>en</strong>d();<br />

}<br />

else<br />

{<br />

myAlert.text = "Print job canceled";<br />

}<br />

For a working example, see “Printing example: Scaling, cropping, and responding” on page 932.<br />

Working with page properties<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

Once the user clicks OK in the Print dialog box and PrintJob.start() returns true, you can access the properties<br />

defined by the printer’s settings. These settings include the paper width, paper height (pageHeight and pageWidth),<br />

and cont<strong>en</strong>t ori<strong>en</strong>tation on the paper. Because these are printer settings, not controlled by the Flash runtime, you<br />

cannot alter these settings; however, you can use them to align the cont<strong>en</strong>t you s<strong>en</strong>d to the printer to match the curr<strong>en</strong>t<br />

settings. For more information, see “Setting size, scale, and ori<strong>en</strong>tation” on page 926.<br />

Setting vector or bitmap r<strong>en</strong>dering<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

You can manually set the print job to spool each page as vector graphics or a bitmap image. In some cases, vector<br />

printing produces a smaller spool file, and a better image than bitmap printing. However, if your cont<strong>en</strong>t includes a<br />

bitmap image, and you want to preserve any alpha transpar<strong>en</strong>cy or color effects, print the page as a bitmap image. Also,<br />

a non-PostScript printer automatically converts any vector graphics to bitmap images.<br />

You specify bitmap printing by passing a PrintJobOptions object as the third parameter of PrintJob.addPage().<br />

For Flash Player and AIR prior to AIR 2, set the PrintJobOptions object’s printAsBitmap parameter set to true, as<br />

follows:<br />

var options:PrintJobOptions = new PrintJobOptions();<br />

options.printAsBitmap = true;<br />

myPrintJob.addPage(mySprite, null, options);<br />

If you don’t specify a value for the third parameter, the print job uses the default, which is vector printing.<br />

Last updated 6/6/2012<br />

925

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!