- First Create a new flash file and save it as PrintTest.fla
- Create the content that you want to print .
- Convert the whole content into a movie clip and give it an instance name of “page_mc”.
- And create the print button. Give it an instance of "printBtn_mc".
- Finally create the “actions” layer. Open the actions panel.
Type the following code.
import flash.events.MouseEvent;
import flash.printing.PrintJob;
import flash.geom.Rectangle;
// on Print function
function onPrint(event:MouseEvent):void{
//a variable to hold new print job
var pj:PrintJob = new PrintJob();
// display Print dialog box, but don’t start the print job unless .start() returns successful
var result:Boolean = pj.start()
if(result){
// add specified page to print job
try{
var rect:Rectangle = new Rectangle(page_mc.x, page_mc.y,page_mc.width, page_mc.height)
pj.addPage(page_mc, rect, null, 0);
}
// in case an error pops up (i.e. printer not connected). warn the user to try again
catch(event:Error){
trace("unable to Print");
}
}
// calls to addPage() was successful. You should always check for successful
pj.addPage(page_mc)
// Finally calling send().
pj.send()
}
printBtn_mc.addEventListener(MouseEvent.CLICK, onPrint);
|| ----------------------------------------------------------------------- ||
Preview
Download .zip
No comments:
Post a Comment