2 Replies Latest reply on Jun 19, 2009 12:42 PM by storyguy88

    Reloading HTMLLoader content from another window

    storyguy88

      I'm writing an AIR app using JavaScript and I am creating a window using air.HTMLLoader.createRootWindow(). When an action happens in this new window I need to refresh the content in all the other app windows, but I don't know how to reference the other windows in a way to reload them, this is my line of thinking on what I need to do:

       

      for (var i in air.NativeApplication.nativeApplication.openedWindows) {
           var w = air.NativeApplication.nativeApplication.openedWindows[i];
           var htmlLoader = ?
           htmlLoader.reload();
      }
      
        • 1. Re: Reloading HTMLLoader content from another window
          Joe ... Ward Level 4

          To do it this way, you will have to look for HTMLLoader instances in the flash display lists of the opened windows:

           

          for (var i in air.NativeApplication.nativeApplication.openedWindows) {
               var w = air.NativeApplication.nativeApplication.openedWindows[i];
               var htmlLoader;
               for( var index = 0;
          index < w.stage.numChildren; index++ )
               {
                   if(
          w.stage.getChildAt( index ) is air.HTMLLoader )
                    {
                         htmlLoader = w.stage.getChildAt( index );
                    }
               {
              
               htmlLoader.reload();
          }

          (untested and unoptimised, but should give you the general idea)

           

          Another way would be to keep a list of references to the HTMLLoader objects as you create them with createRootWindow() and refresh the windows from that list.

          • 2. Re: Reloading HTMLLoader content from another window
            storyguy88 Level 1

            Thanks Joe, was what I was looking for. Your code doesn't quite work, so here is what I ended up with:

            // reload all other windows in the app
            for (var i in air.NativeApplication.nativeApplication.openedWindows) {
                 var window = air.NativeApplication.nativeApplication.openedWindows[i];
                 if (window.active)
                      continue;
                 var child;
                 for (var j = 0; j < window.stage.numChildren; ++j) {
                      child = window.stage.getChildAt(j);
                      if (child.reload)
                           child.reload();
                 }
            }