3 Replies Latest reply on Feb 23, 2009 4:13 PM by Joe ... Ward

    Passing data between parent child window

    verseview Level 1
      I was wondering how to pass data between windows that are opened by Adobe AIR.

      In this application, the parent window opens another native child window. The child window has some text under the DIV section. If the child window is already opened, the parent window should just pass the data to the child window and the child window displays the data.

      Also I want to trigger an event in the parent window from the child window and a data passed from the child window. How do we do this?

      Thanks
      Binu
        • 1. Re: Passing data between parent child window
          anirudhs Level 2
          Hi,

          I'm assuming you're doing an HTML AIR application.

          Parent HTML:

          var dataObj = 1;
          var childWin = null;
          if ( !childWin )
          childWin = window.open('childwin.html');

          and in your childwin.html, you can simply access dataObj by saying window.opener.dataObj.

          You want to notify the parent window of something, just call a function window.opener.yourcallbackFn().

          Hint: To get to the DOM window object from a HTMLLoader, simply call htmlLoaderInstance.window.
          • 2. Re: Passing data between parent child window
            verseview Level 1
            Thanks for the response.

            But I want to create a window with chrome features.
            newWindow = air.HTMLLoader.createRootWindow(true, options, true, presentBounds);
            ....
            newWindow.load(new air.URLRequest("child.html"));

            Now how do I access variables in child.html and how does the child acces variables from parent.

            Thanks
            --Binu
            • 3. Re: Passing data between parent child window
              Joe ... Ward Level 4
              Your newWindow variable is your reference from the parent to the child:
              newWindow = air.HTMLLoader.createRootWindow(true, options, true, presentBounds);
              ....
              newWindow.load(new air.URLRequest("child.html"));

              To get to the JavaScript window object of the child, use newWindow.window.

              createRootWindow() doesn't set a reference to the parent on the child window (hence the "root" in the function name), but you can set it yourself after loading the content. Just set the child parent and opener properties in an event listener for the complete event:

              newWindow.window.parent = newWindow.opener = this;