How to print movieclips using PrintJob in as3

Printing something in Flash isnโ€™t really rocket science, but there are a couple of details that will make your job easier as well as improve the quality of the end result. Today you will learn how to print movieclips using PrintJob in as3 and Adobe Flash.
Basically what we need is to have a movieclip with your vectorial graphic and a button that will trigger the action.

Settings all files


Create a new ActionScript File and save it as “PrintClass.as” (com.fladev.print.PrintClass) โ€“ this will be the main class for our flash file; Create also a new AS3 Flash file (590ร—300px) and open it, so that we have both files opened.

PrintClass

On stage, draw a rectangle with any size, convert this to movieclip and give him an instance name called “btn“. Download something vectorial, something with size let’s say 300x300px, convert this to movieclip and give him an instance name called “mc” too. Now, let’s focus on PrintClass.as

PrintClass.as

[as3]
package com.fladev.print
{
import flash.display.MovieClip;
public class PrintClass extends MovieClip
{
public function PrintClass () {
//adding a listener for button
btn.buttonMode = true;
btn.mouseChildren = false;
btn.addEventListener(MouseEvent.CLICK, printFunction);

}
}
}
[/as3]

Then the printFunction:

[as3]
private function printFunction(e:MouseEvent):void
{
printer = new PrintJob();

var opt:PrintJobOptions = new PrintJobOptions(true);

var printerStarted:Boolean = this.printer.start();
if (printerStarted) {
this.printer.addPage(this.mc, null, opt);
this.printer.send();
this.printer = null;
}
}
[/as3]

Optional you can put “opt.printAsBitmap = true”, but this is unuseless since our movieclip is vector.
Feel free to send me any questions.


Twitter Digg Delicious Stumbleupon Technorati Facebook

7 Responses to “How to print movieclips using PrintJob in as3”

  1. Good tutorial, I’ve had only a few projects in flash that required printing. I’m wondering how many people do actually use print on the flash websites.

  2. In general cred ca proiectele mai hard au si functia asta…it is a must after all.

    Eng: Generally, I think you will find in every big project a function to print something.

  3. Hello!
    I find your tutorials very helpfule!
    But what i really was looking for was the function to print/Capture an area of the flash/movieclip – and add the function to save it as a bitmap image…
    I found those tutorials: 1: http://www.bit-101.com/blog/?p=1415 and 2: http://designreviver.com/tutorials/actionscript-3-jpeg-encoder-revealed-saving-images-from-flash , but as a beginner – it really difficult to understand what to do to get the functions working! Can you please make a tutorial that is understandable to a flash beginner about the subject? It will be really helpfule to all flash beginners out there…
    I’ll be happy with a reply ๐Ÿ™‚
    Thanks!

  4. Hi Mohanad, in future I will do this tutorial too. Until then, send me an email if you have any other question. Thanks!

  5. pls i am a fresh user of flash but i want 2 knw if u can use flash to edit vedio thats changing its background,adding effects etc if posible can you send me tips on how its done

  6. Not sure about the tutorial, but I sure love the WEBDEV logo banner at the bottom