Messing with the PrintJob Class

By sgrosvenor
We teamed up with SiteGround
To bring you the latest from the web and tried-and-true hosting, recommended for designers and developers. SitePoint Readers Get Up To 65% OFF Now

Its the same with anything, until you need to use the functionality of a given class or object in a project, you never delve into it unless you’re an ardent explorer type person!. I found the need to quickly explore the printing capabilities of Flash MX 2004 and was pleasantly surprised.

In Flash MX 2004, the new PrintJob class is much more powerful than the print() and printAsBitmap() functions in previous versions, allowing you to print individual MovieClips, sections of MovieClips (using print area parameters) or entire levels with simplistic ease.

In the example outlined here (source code found here), I needed to quickly print out a given number of MovieClips from the stage (example shown below).

ScreenShot of Stage

I created the following function to pass in a simple array of MovieClips allowing me to add multiple pages to the print queue.

function PrintWhat(WhatToPrint:Array) {
var PrintQueue = new PrintJob();
var PrintStart:Boolean = PrintQueue.start();
if (PrintStart) {
for (i=0; i<=WhatToPrint.length; i++) { PrintQueue.addPage(WhatToPrint);
//Prints Specific MovieClips
PrintWhat([MCPrint, MCPrint002,MCPrint003]);
//Prints a Level

The PrintWhat() function accepts the array of MovieClips or levels as a parameter, start a new print job using the PrintJob object, call the start() method which then triggers the print dialog. The start() method returns a Boolean true or false value based on whether the user clicks ‘OK’ or ‘Cancel’ in the print dialog box, and the inner condition when PrintStart is true is triggered or stepped over.

If the user chose to print and clicks ‘OK’, the incoming WhatToPrint array is parsed, and pages are added to the print queue using the addPage() method and the job is sent to the printer using the send() method.

Note: You can pass extra parameters for printing portions of MovieClips, but I

We teamed up with SiteGround
To bring you the latest from the web and tried-and-true hosting, recommended for designers and developers. SitePoint Readers Get Up To 65% OFF Now
  • sgrosvenor

    I’m going to be blogging on a more code / example orientated approach over the next month(s) as per the previous few posts, although there may be the odd product review slotted in during the time. Enjoy!

  • Richard Leggett

    Interesting thing about PrintJob is that it can only exist over one frame, thought the following thread might clear up any problems people were having with PrintJob (also contains a link to a MM technote on the matte)

  • MRC06460


    I have used the PrintJob class and it does a good job, but their is one capability I cannont find.

    I want to limit the number of copies printed to one. I can get a bunch of information from the print dialog box (Landscape or portrait setting, page and print dimensions in pixels) but I cannot get access to the number of copies set.

    If I had this number, I could abort the print job and say “only one copy allowed”

    Is there any way to control the number of copies printed from within Flash?????



  • blundith

    I have some concerns, mainly how it deals when you need to print a textarea with a text that excels the visible area and needs to be paged.

    It seems that still there is ome room to improve

  • HelpwithFlash

    Does anybody know how one would print a .txt file from a print button within flash? The txt file is in the same directory as the .flv file.

  • Does it work???

    The PrintJob class is ok…

    But does the PrintJob.orientation, PrintJob.paperHeight, PrintJob.paperWidth, PrintJob.pageHeight and PrintJob.pageWidth actually work? It doesn’t seem to be working. If I can get that to work it would be pretty nifty.

    Any thoughts about this? Some sample code would be nice.

  • severiaan

    I want to print mc longer than printer can print in one page, how can i do this?

  • Max

    I want to know how to print longer than one page too. Any ideas. Have gotten nowhere with google.

  • Steve

    Conditionals. If the mc is longer than the pageHeight then add up to pageHeight, then add a second page that starts at pageHeight*2 and goes to pageHeight*3. Just because the functionality may not be build directly into the class doesn’t mean you can’t use the provided tools to accomplish it or even extend the class.

  • Steve

    Actually you would want to do 0 to pageHeight, then pageHeight to pageHeight*2, then pageHeight*2 to pageHeight*3 etc.

  • enrico

    does anybody else have problems with printAsBitmap and the latest flash player?

    i’m using flash 8, publishing for flash 6

    and something as straightforward as:
    printAsBitmap(_root, “bframe”);

    prints fine with older plugins, but prints blank page with on both i.e. and firefox… :(

  • Valentijn

    Yep i got the samen problem…
    Now i need to force customers to install flash 9 :(
    But i’m trying using this function.. hope it helps…


  • roy


    how can i change the oriantation to landscape ?