Printjob Class in FLMX 2004
When it comes to creating rich internet applications, Flash MX 2004 is one of the best tools out there. Building UI in flash can be much more intuitive and easy-to-customize than using HTML. The other major advantage is that data handing runs seamlessly without the user even knowing (that means no more annoying "refresh" screens). And last, it can finally print reports and statistical data.
In previous versions of Flash, you could only print by specifying the frame number on the timeline or by specify a specific area on the stage. It was very frustration, especially whentrying to print dynamic data or lists of information. The PrintJob class helps to solve a lot of issues that I had with printing. Below is code to print a basic page:
| 1 // create PrintJob object 2 var pj:PrintJob = new PrintJob(); 3 4 // displays print dialog. If print is started, then execute the rest of the actions 5 if (pj.start()) { 6 7 //add a page 8 pj.addPage(_root, {xMin:0,xMax:400,yMin:0,yMax:500}) 9 10 // send pages from the spooler to the printer 11 pj.send(); 12 13 } 14 15 // clean up 16 delete pj; // delete object |
In breaking down what this actually does, let's start with line 2. On Line 2, I'm basically creating an instance of the PrintJob class, which store it in an object called 'pj'. On Line 5, the condition checks whether the user clicked 'OK' on whether to print. If they selected 'OK', it will continue with the code. If they selected 'Cancel', it will skip the condition. On Line 8, I am basically adding a page and specifying what it is going to print (_root), and the location and size of the print area. If you wanted, you can add as many pages as you like. On Line 11, it tell the printer to print all the pages that I specified (only one page in this instance). Finally, on line 16, we must delete the print object to free up resources.
You can also apply the PrintJob class to components as well. This is where it works best. Below is a sample DataGrid:
If you would like download the source for this file, click here.

