5 Replies Latest reply on Aug 1, 2012 9:02 AM by afxgroup1976

    Resize a native window content mantain the aspect ratio..

    afxgroup1976

      Hello,

      I'm using this code top open a native window and load an external SWF into it.

       

      var tableWindow:NativeWindow;
      var options:NativeWindowInitOptions = new NativeWindowInitOptions();
      options.systemChrome = NativeWindowSystemChrome.STANDARD;
      options.type = NativeWindowType.UTILITY;
      tableWindow = new NativeWindow(options);
      tableWindow.title = 'MyWin';
      tableWindow.width = 600;
      tableWindow.height = 500;
      tableWindow.stage.color = 0x000000;
      tableWindow.stage.scaleMode = StageScaleMode.NO_SCALE;
      tableWindow.stage.align = StageAlign.TOP_LEFT;
      tableWindow.addEventListener(NativeWindowBoundsEvent.RESIZING, resizeDisplay, false, 0, true);
      tableWindow.addEventListener(Event.CLOSE, closeWin);
      tableWindow.activate();

       

      after opening a window i load the swf into it:

       

      var loader:Loader = new Loader();
      var context:LoaderContext;
      context = new LoaderContext();
      context.allowCodeImport = true;
      context.applicationDomain = new ApplicationDomain();
      loader.load(new URLRequest("app:/myswf.swf"), context);
      loader.contentLoaderInfo.addEventListener(Event.INIT, loadFlash);

       

      I have several problems.. if i use a ScaleMode different than NO_SCALE in main swf and/or in the loaded SWF the file is shown wrong. I have a correct window but the swf is displayed HUGE into the window.. so i've decided to use NO_SCALE as ScaleMode

      Is there a way to mantain the aspect ratio of the window AND (more important) resize ALSO the swf loaded into it?

       

      Thank you

        • 1. Re: Resize a native window content mantain the aspect ratio..
          afxgroup1976 Level 1

          No one?

          Is there a way at least to use EXACT_FIT and use width and height property of window to resize it dinamycally?

           

          I mean. If I use the code above using EXACT_FIT and using this code in the loadFlash function:

           

          var content:DisplayObject = (event.target as LoaderInfo).loader;
          content.scaleX = 72/width;
          content.scaleY = 72/height;
          stage.addChild(content);

           

          The content (the loaded swf) is resized correctly when i resize the window. But if i try to use width and height to size the window the result is horrible... i've read that i should use stageWidth and stageHeight but even using those the result is the same.. so. is there a way to set the size of the window correclty using EXACT_FIT? (if i use NO_SCALE the window is sized corrrectly but not the content..)

          • 2. Re: Resize a native window content mantain the aspect ratio..
            sinious Most Valuable Participant

            I rarely do Flex but I've done a lot of AIR for AS projects and I find their windows to have this bizarre behavior as well.

             

            I think 2 things are important in my limited experience. To keep aspect ratio I set it to NO_BORDER. This maintains the aspect ratio but also allows resizing.

             

            Second on my main class I explicitly set the main SWF to a height and width:

             

            e.g.

            package yada {

             

                 [SWF(width=xxx,height=xxx)]

                 public class MyApp extends.....

             

            If I didn't set that in the AS3 code explicitly (the XML didn't matter at all) the SWF would be the original size. Now your content should be at the size you specify in your window and allow resize.

             

            Lastly, you're already paying attention to resizing:

             

            tableWindow.addEventListener(NativeWindowBoundsEvent.RESIZING, resizeDisplay, false, 0, true);

             

            I think you need to handle that manually. As the user intends to grow or shrink the window you need to override their resize and set the height and width explicitly based on what they try to do, forcing the outer windows size to always be a proper aspect ratio.

            • 3. Re: Resize a native window content mantain the aspect ratio..
              afxgroup1976 Level 1

              the manual resize now is working correctly.. the problem occurs when i try to size the window using the code:

               

              f.e.

               

              win.width=600

              win.height=500

               

              regard the manual resize. on flex i think the only soultion to specify the width and height is using the compiler switch that is able to set width, height, framerate and so on. I don't think it i spossible to add the metadata in the default mxml file

              • 4. Re: Resize a native window content mantain the aspect ratio..
                sinious Most Valuable Participant

                That metadata is for the SWF you're loading in there. You'd just set it to the correct initial size so it shows up how you expect it. After that as you resize its container it should respond appropriately.

                 

                So when you resize the window using code it sounds like the SWF isn't getting a container resize event because the StageScaleMode would dutifully resize itself. That's the only lead I see.

                 

                This threads last few posts might help:

                 

                http://forums.adobe.com/thread/430250

                • 5. Re: Resize a native window content mantain the aspect ratio..
                  afxgroup1976 Level 1

                  The loaded SWF is a flex SWF and so, not created with flash. so the only way to specify width and height is passing that compiler switch.

                  The container is the window itself.. and for a strange thing when using EXACT_FIT or SHOW_ALL the width are calculated in a different way.. based on a scaleX of 72/width and a scaleY of 72/height...

                  Indeed if i use the NO_SCALE option the width=.. and the height=.. working correctly, but for a strange problem it doesn't scale the SWF i've loaded