2 Replies Latest reply on Feb 5, 2009 7:37 AM by htmlkman

    AIRMenuBuilder Question (Third Time's A Charm?)

    htmlkman
      This will be the third time I've posted this same question in various ways. Having received no responses, I'm wondering if anyone out there is actually using AIRMenuBuilder....but here goes anyway:

      Once I've created a root menu with AIRMenuBuilder, can I replace it with another? For example, my initial menu has 5 horizontal, top-level items (A,B,C,D,E). The first four (A,B,C,D) have submenus, but when the fifth (E) is selected, I'd like to overwrite the initial horizontal menu with a new one.

      The menus are created from JSON files, and the onSelect events are handled by Javascript. Running into the "Adobe AIR runtime security violation for JavaScript code in the application security sandbox," I created a parent sandbox bridge. The value of the new JSON file is successfully passed (and displayed in alerts), but I'm still getting a security violation and the new menu does not appear. Relevant snippets below.

      Thanks in advance for any suggestions you could offer.

      Snippet 1 from index.html:

      <script type="text/javascript">
      var root = air.ui.Menu.createFromJSON ("menus/rootmenu.js");
      air.ui.Menu.setAsMenu (root);

      var bridgeInterface = {};
      var newRootMenu = bridgeInterface.newRootMenu;
      bridgeInterface.newMenu = function(newRootMenu){
      var menuSource = "menus/" + newRootMenu + ".js";
      alert(menuSource); // displays properly, with correct values
      root = air.ui.Menu.createFromJSON(menuSource);
      alert('About to put up a new menu...'); // never displays, security violation must be line above
      air.ui.Menu.setAsMenu(root);
      alert('Well, we tried putting up a new menu, but...'); // never displays
      }

      function engageBridge(){
      document.getElementById('contentArea').contentWindow.parentSandboxBridge = bridgeInterface;
      alert('Bridge is engaged!'); // displays properly
      }
      </script>

      Snippet 2 from index.html:
      <iframe
      id="contentArea" name="contentArea" bgcolor="white" width="100%" height="98%"
      src=" http://192.168.x.x/local/ui.html" sandboxRoot=" http://192.168.x.x/local/"
      documentRoot="app:/sandbox/" ondominitialize="engageBridge()"></iframe>

      Snippet from print.js:

      case "E":
      var menuName = "eMenu";
      bridgeInterface.newMenu(menuName);
      break;
        • 1. Re: AIRMenuBuilder Question (Third Time's A Charm?)
          anirudhs Level 2
          :) Third time is lucky. Jokes aside, I apologize for the late response. I forgot to subscribe to the earlier thread.

          You should be able to replace the root menu using the setAsMenu(newMenu, true) call.

          createFromJSON() does an eval() call to parse the JSON object. eval() is only allowed in the application sandbox while the application is starting up. Take a look at JSONDataSource in AIRMenuBuilder.js. If you can modify that to parse the JSON string in any other way other than via eval() (as3corelib has a JSON parser) you'll have what you want.

          In your case, I think simply using the XML way to load a menu should solve your problem. You don't need the bridge.

          P.S: And don't worry, this time I've subscribed to this post. :)
          • 2. Re: AIRMenuBuilder Question (Third Time's A Charm?)
            htmlkman Level 1
            Thanks, anirudhs! Switching from JSON to XML solved my problem.

            I originally switched from XML to JSON because the XML examples in the Adobe docs didn't work for me. Turns out the official docs have uncorrected typos, e.g., the missing question mark in the the XML menu example on page 175 of "Developing Adobe Air 1.5 Applications with HTML and AJAX."