0 Replies Latest reply on Dec 3, 2008 4:56 AM by Matthew_M

    "air" Object undefined, using JavaScript.

    Matthew_M Level 1
      Hello,

      I'm using Adobe Air to extend the functionality of an existing web client (allowing access to file-system, etc). The web client is programmed in JavaScript.

      Because the source code of the web client is pretty big, I would like to avoid code branches. That is, I would like the web client to run in the "improved" mode, if and only if it detects it's running in an Adobe Air environment, otherwise it must behave normally. This makes sense because the number of added functionalities is quite small.

      I started by creating a HTML Air application that displays a login panel with three fields:

      - server
      - username
      - password

      The web client is deployed on a server. I want to avoid packaging the whole web client + server in the Adobe Air application. That doesn't make sense for my purpose. This is the reason why I added a "server" field in the login page: the user can enter the URL of the server he wants to connect to.

      When the user clicks on the login button, the application posts the real login page of the web client (with AJAX) and it gets a session id cookie. Finally, I load the web client with:

      window.location.href = http://www.example.site/path/to/index.jsp

      After this line of code is executed, I can see the web client running in my Air application. Now, to extend its functionality I have to add some Air code in its JavaScript files.

      So I added the following code to the index page.

      <script type="text/javascript" src="path/to/AIRAliases.js"></script>

      and I started editing a JavaScript file:

      if (air) { // We are running in an Air environment
      // improved code
      } else { // We are running in a browser
      // normal code
      }

      The problem is that the "air" object is always undefined. I though this was a problem of AIRAliases.js, but it wasn't the case: "window.runtime" is also undefined.

      It seems like "window.runtime" is undefined after any "window.location.href = ..." instruction.

      Is this normal?
      Is there another way to load a website in an Air application, giving it access to the "air" object?

      Thank you,
      Matthew