Flash Resize the Swf


/ Published in: ActionScript 3
Save to your folder(s)

Ever have to make a swf that needs to change height? Want to use the browser's scrollbar instead of having to create one in flash?


Copy this code and paste it in your HTML
  1. So this requires both flash and javascript code to get it working correctly.
  2.  
  3. The flash:
  4.  
  5. import flash.external.ExternalInterface;
  6. public class Main extends Sprite
  7. {
  8. public function Main()
  9. {
  10. resizeSwf(1000);
  11. }
  12. private function resizeSwf(newSize):void
  13. {
  14. if (ExternalInterface.available)
  15. {
  16. ExternalInterface.call("resizeEmbed", newSize);
  17. }
  18. }
  19. }
  20.  
  21. The JavaScript:
  22. <script language="javascript">
  23. function resizeEmbed(value)
  24. {
  25. var theSwf = getFlashMovie("Main");
  26. theSwf.style.height = value;
  27. }
  28.  
  29. function getFlashMovie(movieName)
  30. {
  31. var isIE = navigator.appName.indexOf("Microsoft") != -1;
  32. return (isIE) ? window[movieName] : document[movieName];
  33. }
  34. </script>
  35.  
  36. So you could call the resizeSwf function anywhere you want, just pass in the height that you want the swf to resize to and the javascript will take care of the rest, automatically adding the scrollbars in your browser.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.