Rectangle 27 0

flash How to resize a .swf file depending on screen size?


Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

If you link directly to the swf file (not embedding it in any page) it'll be full-screen.

Note
Rectangle 27 0

flash How to resize a .swf file depending on screen size?


<script type="text/javascript">
  var w=window.innerWidth, h=window.innerHeight;
  document.write('<object width="' + w + '" height="' + h + '">');
  document.write('  <param name="movie" value="x.swf">');
  document.write('  <embed src="x.swf" width="100%" height="100%"></embed>');
  document.write('</object>');
</script>

If you need to dynamically resize whenever the window is resized then you can attach a handler to the window.onresize event which retrieves the necessary object and embed DOM elements and change their width and height properties. Probably. I haven't tested any of this.

The method for retrieving the window width/height will probably vary per browser but I'm sure you can find a reliable, cross-browser way to do it somewhere online.

Why would you do this instead of just embedding at size "100%"?

You could generate the <object> tag which embeds the SWF file via JavaScript and print the width and height programmatically based on the size of the containing window. For example:

Note