1 Reply Latest reply on Jan 4, 2011 2:58 PM by Joe ... Ward

    calling a function in child window from parent window

    Alex-SM

      Hi,

       

      How can I call a method in child window from parent window in adobe air using javascript. In the following example I need to call mytest() function in

      child.html from parent.html file.

       

      Thanks,

      ASM

       


      //parent.html

      <HTML><HEAD>
      <script>
      var initOptions = new air.NativeWindowInitOptions();
      initOptions.type = air.NativeWindowType.NORMAL;
      initOptions.systemChrome = air.NativeWindowSystemChrome.STANDARD;
      var bounds = new air.Rectangle(300, 300, 600, 500);
      var html2 = air.HTMLLoader.createRootWindow(false, initOptions, false, bounds);
      var urlReq2 = new air.URLRequest("child.html");
      html2.load(urlReq2);
      html2.stage.nativeWindow.activate();

       

      html2.window.mytest();       //NOT WORKING

       

      </script>
      </HEAD><body></body></HTML> 



      // child.html

      <HTML><HEAD>

      <script>

      function mytest()
      {
        air.trace("in child window");
      }

      </script>

      </HEAD> <body></body></HTML>

        • 1. Re: calling a function in child window from parent window
          Joe ... Ward Level 4

          I suspect your problem is that the child window hasn't been created by the time you call the function in the parent.Loading the content is an asynchronous processes -- AIR doesn't stop executing your code until the window has finished loading child.html. So, you will need to add an eventlistener to html2 and call the function from there:

           

          html2.addEventListener( "complete", onChildLoaded );

           

          function onChildLoaded( event )

          {

               html2.window.mytest();

          }