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

Printing a page<br />

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

You use an instance of the PrintJob class to handle printing. To print a basic page through Flash Player or AIR, you<br />

use these four statem<strong>en</strong>ts in sequ<strong>en</strong>ce:<br />

new PrintJob(): Creates a new print job instance of the name you specify.<br />

PrintJob.start(): Initiates the printing process for the operating system, calling the print dialog box for the user,<br />

and populates the read-only properties of the print job.<br />

PrintJob.addPage(): Contains the details about the print job cont<strong>en</strong>ts, including the Sprite object (and any<br />

childr<strong>en</strong> it contains), the size of the print area, and whether the printer prints the image as a vector or bitmap. You<br />

can use successive calls to addPage() to print multiple sprites over several pages.<br />

PrintJob.s<strong>en</strong>d(): S<strong>en</strong>ds the pages to the operating system’s printer.<br />

So, for example, a simple print job script is (including package, import and class statem<strong>en</strong>ts for compiling):<br />

package<br />

{<br />

import flash.printing.PrintJob;<br />

import flash.display.Sprite;<br />

}<br />

public class BasicPrintExample ext<strong>en</strong>ds Sprite<br />

{<br />

var myPrintJob:PrintJob = new PrintJob();<br />

var mySprite:Sprite = new Sprite();<br />

}<br />

public function BasicPrintExample()<br />

{<br />

myPrintJob.start();<br />

myPrintJob.addPage(mySprite);<br />

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

}<br />

Note: This example is int<strong>en</strong>ded to show the basic elem<strong>en</strong>ts of a print job script, and does not contain any error handling.<br />

To build a script that responds properly to a user canceling a print job, see “Working with exceptions and returns” on<br />

page 924.<br />

To clear a PrintJob object’s properties for any reason, set the PrintJob variable to null (as in myPrintJob = null).<br />

Last updated 6/6/2012<br />

923

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

Saved successfully!

Ooh no, something went wrong!