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).
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?





May 28th, 2004 at 6:59 am
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!
May 28th, 2004 at 7:34 am
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) http://chattyfig.figleaf.com/ezmlm/ezmlm-cgi?1:sss:111437#b
January 8th, 2005 at 8:49 am
Hi,
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?????
Thanks,
MikeC
April 4th, 2005 at 8:37 am
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
April 11th, 2005 at 1:37 pm
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.
May 8th, 2005 at 10:25 am
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.
May 20th, 2005 at 4:53 am
I want to print mc longer than printer can print in one page, how can i do this?
December 12th, 2005 at 3:49 pm
I want to know how to print longer than one page too. Any ideas. Have gotten nowhere with google.
March 30th, 2006 at 3:22 pm
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.
March 30th, 2006 at 3:23 pm
Actually you would want to do 0 to pageHeight, then pageHeight to pageHeight*2, then pageHeight*2 to pageHeight*3 etc.
May 25th, 2006 at 11:02 pm
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 8.0.24.0 on both i.e. and firefox… :(
August 17th, 2006 at 12:27 am
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…
Laters
March 14th, 2007 at 7:33 pm
hi
how can i change the oriantation to landscape ?