User Guide
490 Printing
Working with exceptions and returns
You should check to see if the PrintJob.start() method returns true before executing
addPage() and send() calls, in case the user has cancelled the print job. A simple way to
check whether these methods have been cancelled before continuing is to wrap them in an
if
statement, as follows:
if (myPrintJob.start())
{
// addPage() and send() statements here
}
If PrintJob.start() is true, meaning the user has selected Print (or Flash Player has
initiated a Print command), the
addPage() and send() methods can be called.
Also, to help manage the printing process, Flash Player now throws exceptions for the
PrintJob.addPage() method, so that you can catch errors and provide information and
options to the user. If a
PrintJob.addPage() method fails, you can also call another
function or stop the current print job. You catch these exceptions by embedding
addPage()
calls within a
try..catch statement, as in the following example. In the example, [params]
is a placeholder for the parameters specifying the actual content you want to print.
if (myPrintJob.start())
{
try
{
myPrintJob.addPage([params]);
}
catch (e:Error)
{
// Handle error,
}
myPrintJob.send();
}
Once the print job starts, you can add the content using PrintJob.addPage() and see if that
generates an exception (for example, if the user has cancelled the print job). If it does, you can
add logic to the
catch statement to provide the user (or Flash Player) with information,
options, or you can stop the current print job. If you add the page successfully, you can
proceed to send the pages to the printer using
PrintJob.send().