0 Replies Latest reply on Jan 19, 2011 2:13 PM by retrocane

    Can't Access PDF with AIR and JavaScript

    retrocane

      I am simply trying to see an Alert popup in a PDF that contains a value given to it by the ActionScript by way of JavaScript. I don't know where I'm going wrong.

       

      parts: Adobe AIR application file PDF.mxml, test.html contains JavaScript and calls the PDF, sample.pdf simply has a textfield and contains JavaScript.

       

      PDF.mxml successfully loads test.html and calls the function notifyPDF (the alert pops up), passing a string value which appears in the alert. But that function does not seem to pass the string onto the PDF as I do not see the expected alert there.

       

      test.html code:

       

      <html>
          <head>
          <title>notifyPDF</title>
          <script>
              function noftifyPDF(myString) {
                  pdfObject = document.getElementById("PDFObj");
                  try {
                      alert(myString);
                      pdfObject.postMessage([myString]);
                  }
                  catch (e) {
                      alert( e.message );
                  }
              }
          </script>
          </head>
          <body>
              <object id="PDFObj" data="sample.pdf" type="application/pdf" width="100%" height="100%"/>
          </body>
      </html>

       

      JavaScript set in the function myOnMessage in the sample.pdf document:

       

      this.hostContainer.messageHandler = {onMessage: myOnMessage}; 
      function myOnMessage(aMessage)
      {
          if(aMessage[0] == "testMsg")
          {
              app.alert("Test message: " + aMessage[1]);
          }
          else
          {
              app.alert("Error");
          }

      }

       

      I do not get either "Test message:"  nor "Error" when the call is made in the AIR application via a button click.

       

      I am using version 9.4.1 of Adobe Acrobat and Flash Builder 4. What am I missing?

      Thank you in advance.

      Josh