views:

922

answers:

2

I have a flex/as3 project in which I have a bitmap background, and then draw Sprites over top of that background. It creates a map and a route to locations on the map. I am implementing a print function to print that map(the flash screen) and then adding other information to the same page. The map displays with a width of 800px and a height around 480px on a computer screen.

I have looked in the PrintJob class in AS3 and found a way to print a separate bitmap or sprite but I would really just like to create a screen capture of the flash file and then save that as a png. to display separately on a new page with additional information. I know that saving the screen capture as a .png is a different problem but If I could figure out how to capture the stage in the first place the second problem would cease to be.

+1  A: 

You would need to wrap everything that was on the stage in a Sprite instance and then pass that Sprite to PrintJob.addPage() method.

If you're using Flex then you can also use the FlexPrintJob class to handle some of the layout and pagination for you.

Sly_cardinal
A: 

Hi I was trying to print the Stage and stumbled with a lot of problems getting the stage to resize properly so I use a combination of solutions, that involved converting the stage to a bitmap.

Here my source:

function PrintStage(evt:MouseEvent) {
   var printJob:PrintJob = new PrintJob();
   var options:PrintJobOptions = new PrintJobOptions();
   options.printAsBitmap = true;
   trace("print called!");
   if (printJob.start()) {
    var printSprite = new Sprite();

    var bitmapData:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight);
    bitmapData.draw(stage);
    var screenShot:Bitmap = new Bitmap(bitmapData);

    printSprite.addChild(screenShot);

    //========== printjob bug fix - prevent blank pages: ==========
    printSprite.x = 2000; //keep it hidden to the side of the stage
    stage.addChild(printSprite); //add to stage - prevents blank pages
    //=============================================================

    trace("before printSprite width: " + printSprite.width + " printJob.pageWidth: " + printJob.pageWidth);

    //scale it to fill the page (portrait orientation):
    var myScale:Number;
    myScale = Math.min(printJob.pageWidth/printSprite.width, printJob.pageHeight/printSprite.height);
    printSprite.scaleX = printSprite.scaleY = myScale;
    var printArea:Rectangle = new Rectangle(0, 0, printJob.pageWidth/myScale, printJob.pageHeight/myScale);

    trace("after printSprite width: " + printSprite.width + " printJob.pageWidth: " + printJob.pageWidth);

    printJob.addPage(printSprite,printArea,options);
    printJob.send();

    stage.removeChild(printSprite);
    printSprite = null;
   }
  }

Hope it helps someone....

Vlax