Printing a 2D element makes stage3d view disappear

309 views Asked by At

I have an application that consist of a 3D view and some 2D views. The problem occurs when I try to print one of the 2D views. The 3D view disappears after the printing has been performed.

I have replicated the problem with the Basic_Load3DS example from the Away3D. I added a red button for initiating the print job. The PrintJob prints the button and has nothing to do with the 3D view but the ant disappears after the printing is done.

You can try it here. Click on the red button and then OK in the printing dialogue that appears for the problem to occur. View source is available.

Here is the code that I added to the Basic_Load3DS example

private var _btn:Sprite;
protected function initExtra():void
{
 _btn = new Sprite();
 addChild(_btn);
 _btn.graphics.beginFill(0xff0000);
 _btn.graphics.drawRect(0, 0, 100, 100);
 _btn.y = 100;
 _btn.addEventListener(MouseEvent.CLICK, print);
}
protected function print(e:Event):void
{
 var tPJ:PrintJob = new PrintJob();
 if (tPJ.start())
 {
  tPJ.addPage(_btn); //This line cause the problem
  tPJ.send();
 }
} 

Nothing goes wrong if I comment out the line tPJ.addPage(_btn); 

Any ideas on how to solve this problem? I’m in urgent need of a solution!

1

There are 1 answers

2
ansiart On

If you're trying to draw the entire 3D scene, you're trying to draw something that exists on the GPU, and not the CPU. You'll have to draw the scene into a bitmap, then print it.

flash.display.Context3D.drawToBitmapData;

Secondly, you're just drawing a button? Try creating a bitmap, then using drawtobitmapdata, then draw the stage -- this should give you the desired results.