Blog Post RSS ?

Blogs » Flash » Messing with the PrintJob Class
 

Messing with the PrintJob Class

by sgrosvenor

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); } PrintQueue.send(); } } //Prints Specific MovieClips PrintWhat([MCPrint, MCPrint002,MCPrint003]); //Prints a Level //PrintWhat([0]);

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’m not going into that here

It’s as simple as that, and i hope you find it useful! Who said printing was boring?

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Ping.fm
  • Twitthis

Related posts:

  1. CSS Frameworks and Semantic Class Names CSS frameworks often contain crufty, non-semantic code. Does it have...
  2. Fixing Object Instances in JavaScript Even experienced coders can get caught out by object handling...
  3. Attention Class! How Teaching As A Side Gig Can Benefit You (and Others) Teaching is a great way to use your skills and...
  4. Microsoft Fix Their Non-Random Browser Choice Screen According to several reports during the past week, Microsoft's browser...
  5. Debug PHP with Firebug and FirePHP If you're anything like me, you'd sooner forgo water than...

This post has 13 responses so far