0 Replies Latest reply on Dec 1, 2011 1:05 AM by Niall O'Donovan

    PDF Component

    Niall O'Donovan Level 7

      Hi,

       

      I have a component that is intended appear in one state and display various PDFs. I have it working when it is called the first time, however when it is called subsequently it does not load the PDF.

       

      I have been using the Tour de Flex approach of using a mx:HTML to show the PDF, but changed to adding elements to a spark container:

       

      private var pdfHTMLLoader:HTMLLoader = new HTMLLoader();

      private var pdfUIC:UIComponent;

       

                                    private function loadPDF():void {

        // Check to see if Adobe Reader 8.1 or higher is installed

        // Possible values:

        //         HTMLPDFCapability.STATUS_OK

        //         HHTMLPDFCapability.ERROR_INSTALLED_READER_NOT_FOUND

        //         HTMLPDFCapability.ERROR_INSTALLED_READER_TOO_OLD

        //         HTMLPDFCapability.ERROR_PREFERRED_READER_TOO_OLD

                                              if(HTMLLoader.pdfCapability == HTMLPDFCapability.STATUS_OK) 

                                              {

        // Use FlexGlobals variable for PDF name

                                                        var pdfRequest:URLRequest = new URLRequest(FlexGlobals.topLevelApplication.currentPDF);

       

                                                        pdfHTMLLoader = new HTMLLoader();

                                                        pdfHTMLLoader.width = pdfWin.width;

                                                        pdfHTMLLoader.height = pdfWin.height;

                                                        pdfHTMLLoader.load(pdfRequest);

       

                                                        pdfUIC = new UIComponent();

                                                        pdfUIC.addChild(pdfHTMLLoader);

                                                        pdfUIC.name = "PDFView";

       

                                                        pdfWin.addElement(pdfUIC); // Add the element to the pdfWin spark container

       

                                              } else {

                                                        Alert.show("PDF cannot be displayed. Error code:" + HTMLLoader.pdfCapability);

                                              }

                                    }

       

        // Called if window is resized

                                    private function reloadPDF():void {

                                              pdfHTMLLoader.width = pdfWin.width;

                                              pdfHTMLLoader.height = pdfWin.height;

                                              pdfHTMLLoader.reload();

                                    }

       

                                    protected function backButton_clickHandler(event:MouseEvent):void

                                    {

                                              pdfWin.removeAllElements();

                                              flash.system.System.gc();

       

                                              var eventObject:Event = new Event("hidePDF");

                                              dispatchEvent(eventObject);

                                    }

       

       

      I think that the problem may be in either removing the elements or in how I am adding the HTMLLoader to the UI Component and then adding the element to the spark container.

       

      adl1.png

       

      adl2.png

       

      Thanks,

       

      Niall