Resize Flash at runtime

Posted in Flash at 9:14 pm by Madarco

If your content is bigger than the average screen size, using a flash scrollbar for the entire document is really slow and not user-friendly, so its better to enlarge flash to fit the content and scroll the entire page with the browser's scroll bar.

Put the flash object in a div:

HTML:
  1. ...
  2. <SCRIPT LANGUAGE="JavaScript">
  3. <!--
  4. function newSize(width,height) {
  5.     if(document.all && !document.getElementById) {
  6.       document.all['myflash'].style.pixelWidth = width;
  7.       document.all['myflash'].style.pixelHeight = height;
  8.     }else{
  9.         document.getElementById('myflash').style.width = width;
  10.         document.getElementById('myflash').style.height = height;
  11.     }
  12. }
  13. //-->
  14. </script>
  15. </head>
  16. <div id="myflash" style="position:relative; width:100%; height:100%; z-index:1; min-width:1000px;">
  17.  ...
  18. </object>
  19. </div>

and in the movie do:

Actionscript:
  1. getURL("javascript:newSize('1000px', '100%')");

Other info here

4 Responses to “Resize Flash at runtime”

  1. Madarco DevBlog » Blog Archive » Scroll browser window inside Flash Says:

    [...] I've found that resizing a flash movie to fit his content has a little drawback: the mouse wheel doesn't work when the movie has focus, and in my case the movie has width: 100%. Luckily I've found a nice javascript to scroll the page. [...]

  2. flashman Says:

    This was pretty helpful stuff, thanks!

  3. LadySamG Says:

    Hi,
    I tried your code and it works fine in a mozilla firefox browser, but not with IE7. Is there some part of this code that IE7 doesn't like?

  4. Madarco Says:

    I don't know, it seems to work to me, but if you find some problem let me know

Leave a Reply

Antispam: