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 />

Flash runtime tasks and system printing<br />

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

Because Flash runtimes dispatch pages to the operating system’s printing interface, be aware of the tasks managed by<br />

Flash runtimes and the tasks managed by an operating system’s own printing interface. Flash runtimes can initiate a<br />

print job, read some of a printer’s page settings, pass the cont<strong>en</strong>t for a print job to the operating system, and verify if<br />

the user or system has canceled a print job. Other processes, such as displaying printer specific dialog boxes, canceling<br />

a spooled print job, or reporting on the printer’s status, are all handled by the operating system. Flash runtimes are able<br />

to respond if there is a problem initiating or formatting a print job, but can report back only on certain properties or<br />

conditions from the operating system’s printing interface. As a developer, your code needs to respond to these<br />

properties or conditions.<br />

Working with exceptions and returns<br />

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

Check to see if the PrintJob.start() method returns true before executing addPage() and s<strong>en</strong>d() calls, in case<br />

the user has canceled the print job. A simple way to check whether these methods have be<strong>en</strong> canceled before<br />

continuing is to wrap them in an if statem<strong>en</strong>t, as follows:<br />

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

{<br />

// addPage() and s<strong>en</strong>d() statem<strong>en</strong>ts here<br />

}<br />

If PrintJob.start() is true, the user selected Print (or a Flash runtime, such as Flash Player or AIR, has initiated a<br />

Print command). So, the addPage() and s<strong>en</strong>d() methods can be called.<br />

Also, to help manage the printing process, Flash runtimes throw exceptions for the PrintJob.addPage() method, so<br />

that you can catch errors and provide information and options to the user. If a PrintJob.addPage() method fails,<br />

you can also call another function or stop the curr<strong>en</strong>t print job. You catch these exceptions by embedding addPage()<br />

calls within a try..catch statem<strong>en</strong>t, as in the following example. In the example, [params] is a placeholder for the<br />

parameters specifying the actual cont<strong>en</strong>t you want to print:<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 />

After the print job starts, you can add the cont<strong>en</strong>t using PrintJob.addPage() and see if that g<strong>en</strong>erates an exception<br />

(for example, if the user has canceled the print job). If it does, you can add logic to the catch statem<strong>en</strong>t to provide the<br />

user (or the Flash runtime) with information and options, or you can stop the curr<strong>en</strong>t print job. If you add the page<br />

successfully, you can proceed to s<strong>en</strong>d the pages to the printer using PrintJob.s<strong>en</strong>d().<br />

Last updated 6/6/2012<br />

924

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

Saved successfully!

Ooh no, something went wrong!