Posted By

cessnajumpin on 04/22/10


Tagged

javascript resize actionscript flash swf


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

socialflasher
ballen205


Flash Resize the Swf


 / Published in: ActionScript 3
 

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?

  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  

You need to login to post a comment.