1 Reply Latest reply on Feb 14, 2008 8:37 PM by Sreenivas R

    How to print a dynamically added component?

    Novian Level 1
      Hi there,

      Here's my situation: I've used AS to add components (labels, textfields, datagrid) and dynamic data to a canvas. I thought I could simply use the FlexPrintJob to print what was on the canvas. Unfortunately, the dynamically added components don't print. From what I understand, you can't print displayObjects like my dynamically added components. How on earth can I print these? Any help/advice you can offer will be greatly appreciated.

      Thanks.

      Novian
        • 1. Re: How to print a dynamically added component?
          Sreenivas R Adobe Employee
          I tried the following sample and it seems to work.

          quote:


          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical"
          creationComplete="populateCanvas()">

          <mx:Script>
          <![CDATA[
          import mx.containers.VBox;
          import mx.containers.Canvas;
          import mx.printing.FlexPrintJob;
          import mx.controls.Button;

          var printable:Canvas;
          private function populateCanvas():void
          {
          printable = new Canvas();
          var b1:Button = new Button();
          b1.label = "MyButon";
          b1.x = 10;
          b1.y = 10;
          b1.width = 150;
          b1.height = 25;
          printable.width = 500;
          printable.height = 500;
          printable.addChild(b1);
          //these can be uncommented
          //printable.visible = false;
          //printable.includeInLayout = false;
          addChild(printable);
          }

          private function printCanvas():void
          {
          var fp:FlexPrintJob = new FlexPrintJob();
          if(fp.start())
          {
          printable.width = fp.pageWidth;
          printable.height = fp.pageHeight;
          printable.validateNow();
          fp.addObject(printable);
          fp.send();
          }
          }
          ]]>
          </mx:Script>

          <mx:Button label="Print" click="printCanvas()" />

          </mx:Application>