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.
Filed under: Actionscript 3.0, General, Printing | Tagged: actonscript 3, addPage, as3, as3 printing, as3 printjob, flash cs3 printing, how to print as3, how to print in flash cs3, print movieclip, print with as3, PrintJob, start, try catch | 6 Comments »