4 Replies Latest reply on Feb 16, 2010 1:19 PM by Potericki

    Auto scaling nativeWindow

    Potericki

      Hi,

       

      I want create new Html based nativeWindow and fit window size to html content. How can I do this? I tried use contentWidth and contentHeight property but they have not correct values.

       

      Sample:

       

          var options = new air.NativeWindowInitOptions();
          options.systemChrome = "standard"
          options.type = "normal"
          
          var windowBounds = new air.Rectangle(0, 0, 200, 200);
          newHTMLLoader = air.HTMLLoader.createRootWindow(true, options, true, windowBounds);

       

          newHTMLLoader.load(new air.URLRequest(url));
              newHTMLLoader.addEventListener(air.Event.COMPLETE, function(){
                  air.Introspector.Console.log(newHTMLLoader.contentWidth); // show 0

                  air.Introspector.Console.log(newHTMLLoader.contentHeight); // show 0
              });

        • 1. Re: Auto scaling nativeWindow
          Dragos GEORGITA Adobe Employee

          Hi,

          Can you tell me what's the URL that you're trying to load?

          Also, are you using AIR 1.5.3 or AIR 2 beta2?

           

          Thanks,

          Dragos Georgita | Adobe AIR Engineering

          • 2. Re: Auto scaling nativeWindow
            Potericki Level 1

            I'm using AIR 1.5.3 and working on HTML/AJAX based application.

            The url variable is external web page like http://adobe.com or any other site.

            • 3. Re: Auto scaling nativeWindow
              Dragos GEORGITA Adobe Employee

              Hi again,

               

              I just checked and it seems to be an issue how those values are reported on AIR 1.5.3.

              The values are reported correctly when you opt in for not drawing the scrollbars of the new NativeWindow created.

              This issue is fixed on the latest AIR 2 beta2.

               

              Meanwhile, here's a possible workaround:

               

              var options = new air.NativeWindowInitOptions();

              options.systemChrome = "standard"

              options.type = "normal"

               

              var windowBounds = new air.Rectangle(0, 0, 200, 200);

              // (optional) make the window invizible while the content gets loaded (the first "false" in the parameters)

              // make sure you opt in for not drawing the scrollbars (second "false" in the parameters) to bypass the issue with contentSize reporting

               

              newHTMLLoader = air.HTMLLoader.createRootWindow(false, options, false, windowBounds);

              newHTMLLoader.width = 200;

              newHTMLLoader.height = 200;


              newHTMLLoader.load(new air.URLRequest(url));

              newHTMLLoader.addEventListener(air.Event.COMPLETE, function(){

                    newHTMLLoader.removeEventListener(air.Event.COMPLETE, arguments.callee);

                    // resize the window to fit

                    newHTMLLoader.stage.stageWidth = newHTMLLoader.contentWidth;

                    newHTMLLoader.stage.stageHeight = newHTMLLoader.contentHeight;

               

                    newHTMLLoader.stage.nativeWindow.activate();

              });

              Hope this helps,
              Regards,
              Dragos

              • 4. Re: Auto scaling nativeWindow
                Potericki Level 1

                Hi,

                 

                almost works. You can't set:

                 

                newHTMLLoader.width = 200;

                newHTMLLoader.height = 200;

                 

                because then newHTMLLoader.contentWidth and newHTMLLoader.contentHeight has those values.

                 

                Thanks for help.