1 Reply Latest reply on Nov 29, 2007 4:03 PM by illtrax

    Full-screen swf wont auto-resize until browser window is resized

    illtrax Level 1
      Hello All,
      I posted me test here at http://www.urbanlinx.com/Test.swf.
      I have 4 MCs in the movie. A header, content box (center), footer, and background image.
      When the browser is scaled the background scales in proportion to the widow and keeps its aspect ratio.
      My problem: when the clip is first loaded, the background does not resize until the browser is manualy resized by the user.
      Is there some code I can add that will check the window size before the movie loads?

      My code is attached.
      stop();

      Stage.scaleMode = "noscale";
      Stage.align = "tl";
      Stage.addListener({onResize:reposition});


      function reposition() {
      var header = _root.myHeader_mc;
      var bg = _root.image_mc;
      var content = _root.myContent_mc;
      var footer = _root.myFooter_mc;

      var nPos;

      nPos = getNewPosition(header);
      header._x = nPos.x;
      header._y = 0;

      nPos = getNewPosition(content);
      content._x = nPos.x;
      content._y = nPos.y;

      nPos = getNewPosition(bg);
      bg._x = nPos.x;
      bg._y = nPos.y;

      nPos = getNewPosition(footer);
      footer._x = nPos.x;
      footer._y = Stage.height - footer._height;
      };

      function getNewPosition(mc) {
      var newX = Math.floor((Stage.width - mc._width) / 2);
      var newY = Math.floor((Stage.height - mc._height) / 2);
      return {x:newX, y:newY};
      };

      reposition();

      Stage.scaleMode = "noScale";
      //Auto Resize
      stageListener = new Object();
      stageListener.onResize = function() {
      backgroundResize(_root.image_mc);
      };
      Stage.addListener(stageListener);
      //Background Resize
      function backgroundResize(image) {
      var imageHeight = 400;
      var imageWidth = 700;
      var wRatio = Stage.width/imageWidth;
      var hRatio = Stage.height/imageHeight;
      //Larger Ratio
      if (wRatio>hRatio) {
      var ratio = wRatio;
      } else {
      var ratio = hRatio;
      }
      //Resize
      if (Stage.width<=imageWidth && Stage.height<=imageHeight) {
      image._width = imageWidth;
      image._height = imageHeight;
      } else {
      image._width = imageWidth*ratio;
      image._height = imageHeight*ratio;
      }
      }
      backgroundResize(_root.image_mc);

      Special thanks in advanced.

      PS: if you know a way to accomplish this with cleaner code, the help would be greatly appreciated... if it is already good code... thanks to all the people in the community who taught me :)
        • 1. Re: Full-screen swf wont auto-resize until browser window is resized
          illtrax Level 1
          Well after a whole lot of trails and just as many errors I figured out the resize code is not liking the reposition code. Tried another reposition code and its running great. It's also a lot smoother during resize.

          Here is the code I am using. Basically the background scales in proportion to the browser window, keeps its ratio, and scales from the center. If anyone has tips on how to do this an easier way please drop me a line.