Printing with AS3 PrintJob
This is some basic code to get started with printing in as3. Printing isn’t the easiest thing to do in flash and is something that hasn’t been improved upon too much throughout the years. Maybe with the next release of flash printing will become easier.
function printMe(e:MouseEvent):void
{
//a variable to hold your new print job
var my_pj:PrintJob = new PrintJob();// display Print dialog box, but don’t start the print job unless .start() returns successful
if (my_pj.start())
{
// add specified page to print job
// repeat once for each page to be printed
try
{
//you must have a moveclip to print (i.e. if you want to print a yext field, put it in a movieclip
//and THEN print it)
my_pj.addPage(print_mc_2);
}
catch (e:Error)
{
// in case an error pops up (i.e. printer not connected). warn the user to try again
// or get a “system adminstrator”
print_mc.questionField_txt.text = “There is something wrong with your printer or the connection to your printer. Please contact your administrator and try again.”;
}
// send pages from the spooler to the printer, but only if one or more
// calls to addPage() was successful. You should always check for successful
// calls to start() and addPage() before calling send().
my_pj.send();
}
}
I will write a more advanced article later about page orientation etc. and other (better) way to print in flash with AS3.
About this entry
You’re currently reading “Printing with AS3 PrintJob,” an entry on Gena’s Blurb
- Published:
- March 16, 2009 / 12:55 pm
- Category:
- Actionscript 3.0, General, Printing, flash cs3
No comments yet
Jump to comment form | comments rss [?] | trackback uri [?]