Home / Tutorials / ActionScript / How to print in AS3 /

Flash Tutorials

How to print in AS3 - Tutorial

Posted by : Techload on Dec 02, 2010

 

5.0/5

The PrintJob class lets print swf content to one or more pages.

This class lets you render content that is visible, dynamic or off-screen to the user, prompt users with a single Print dialog box, and print an unscaled document with proportions that map to the proportions of the content.

For more info visit this link: PrintJob

Steps:

  1. Create a new Flash file (Actionscript 3.0) and save it as print.fla.

  2. On the first frame of the Timeline crate any content you awant ( text or / and shapes ). Select all the objects and convert them into a single movie clip and give it an instance name of content.

  3. Create the print button ( using the flash internal components ). Give it an instance of _print.

  4. Press F9 to bring up the Actionscript editor window. First add a Click event listener to the button that will handle the print function:

    _print.addEventListener(MouseEvent.CLICK,Print);

then create the Print() function.

  function Print(e:MouseEvent):void
  {
        var printJob:PrintJob = new PrintJob();

        if (printJob.start()) 
        {

             if (content.width>printJob.pageWidth) {
            content.width=printJob.pageWidth;
            content.scaleY=content.scaleX;
        }

         printJob.addPage(content);
        printJob.send();
}
}

And that's it. You can now test the project.


Thanks for checking out this tutorial and hope you found it useful an easy to follow. If you have questions or just want to let me know it worked for you, drop a comment below anytime.

Visit my portfolio to see what else I'm working on.

Techload

no comment

Add comment

Please login to post comments.