RSS

Flash Printing Basics

Actionscript 3 | Posted on Apr 16 2009

This tutorial will let you understand the capabilities of printing in Flash.

Page Orientation

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 {
            if(my_pj.orientation == PrintJobOrientation.LANDSCAPE) {
              if(print_mc.width<print_mc.height) {
                //we just detected that our printed sprite is actually portrait in it's layout.
                print_mc.rotation=90;
              }
            } else if(print_mc.height<print_mc.width) {
                //we just detected that our printed sprite is landscape in nature but our page is portrait
                print_mc.rotation=90;
            }
            // 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.addPage(print_mc);
            my_pj.send();
           
            //reset just in case it is also displayed on screen.
            print_mc.rotation=0;
           
        } catch (e:Error) {
            // in case an error pops up (i.e. printer not connected). warn the user to try again
            questionField_txt.text = "There is something wrong with your printer or the connection to your printer. Please contact your administrator and try again.";
        }
    }
}

btn_print.addEventListener(MouseEvent.MOUSE_DOWN,printMe);

Multi Page Printing

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 {
            for (var n:Number=1; n<3; n++) {
                var printTarget = this["print_mc" + n]
                if(my_pj.orientation == PrintJobOrientation.LANDSCAPE) {
                  if(printTarget.width<printTarget.height) {
                    //we just detected that our printed sprite is actually portrait in it's layout.
                    printTarget.rotation=90;
                  }
                } else if(printTarget.height<printTarget.width) {
                    //we just detected that our printed sprite is landscape in nature but our page is portrait
                    printTarget.rotation=90;
                }
                // 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.addPage(printTarget);
                //reset just in case it is also displayed on screen.
                printTarget.rotation=0;
            }
            my_pj.send();
           
        } catch (e:Error) {
            // in case an error pops up (i.e. printer not connected). warn the user to try again
            questionField_txt.text = "There is something wrong with your printer or the connection to your printer. Please contact your administrator and try again.";
        }
    }
}

btn_print.addEventListener(MouseEvent.MOUSE_DOWN,printMe);

Download the source code

Live Wall

Actionscript 3 | Posted on Apr 08 2009

Recently working on putting up a show at Arachnid, a greeting application for visitor to interact with various applications with motion tracking called Live Wall. The idea is to use pixel data from the webcam and analyzing it by comparing old and new snaps to locate movement. With the hand movements to navigate or interact the cursor to application they want to go.

Video demostration