0 Replies Latest reply on Oct 16, 2009 6:59 AM by joshua_shizny

    Can not get dynamically loaded image to print

    joshua_shizny Level 1

      I'm losing my mind here.  This used to work.  I have an array of base64 encoded strings that I convert to an array of byte arrays.  Then I load each byte array into am image source and place that image in both an array (for looping through and printing later) and a Box, so that it is actually visiible for printing.  I'm getting a blank sheet of paper every time.  I can see the image on the display though.  Anybody know what I am doing wrong.  Can I not add the image to a DisplayObject and an array?  Do I have to print directly off displayObject (have not had to do that before).. Below are three simple functions I use to create the images and print them.  Please, any help would be great cause I am at a loss

       

                public function createImages():void {
                          this.currentCount = 0;
                          var printLabels:Array = this.labelImageArray[0] as Array;
                          for (var i:int = 0; i < printLabels.length; i++) {
                              var currentLoader:Loader = new Loader();
                              currentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, addToScreen);
                              currentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadFailure);
                              currentLoader.loadBytes(printLabels[i]['imageByteArray'] as ByteArray);
                          }
                      }
                     
                      public function loadFailure(error:IOErrorEvent):void {
                          Alert.show("Failure loading label for print job","Print Failed");
                      }
                     
                      public function addToScreen(event:Event):void {
                          var currentImage:Image = new Image();
                          var currentLoaderInfo:LoaderInfo = event.currentTarget as LoaderInfo;
                          currentImage.source = currentLoaderInfo.content;
                     
                          this.labelContainer.addChild(currentImage);
                          this.labelsToPrint.push(currentImage);
                          this.currentCount++;
                          if (this.currentCount == (this.labelImageArray[0] as Array).length) {
                              this.labelContainer.validateDisplayList();
                              this.validateDisplayList();
                              printLabels();
                          }
                      }
                     
                             
                      public function printLabels():void {
                          var pj:FlexPrintJob = new FlexPrintJob();
                          
                           var pjStart:Boolean = pj.start();
                         
                          if (pjStart == true) { 
                              for (var i:int     = 0; i < this.labelsToPrint.length; i++) {
                                  var currentPage:Image = (this.labelsToPrint[i] as Image);
                                 
                                    try {
                                        pj.addObject(currentPage);
                                  }
                                  catch(e:Error)
                                  {
                                      var err:Error = e;
                                  }
                              }
                              pj.send();
                          }
                          else {
                              showMessage(MessageStrings.PRINT_JOB_FAILED_DETAIL, MessageStrings.PRINT_JOB_FAILED_TITLE);
                          }
                          closeLabels();
                      }