How to Set Stage Size via ActionScript

When Web developers embed a Flash movie in a Web page, they indicate the width and height, or stage size, of the movie. Sometimes, it may be necessary to dynamically change these dimensions in the Flash ActionScript code. By using Flash's ExternalInterface class coupled with some JavaScript code, developers can achieve this effect using only a few lines of code. The ExternalInterface class API allows Flash movies to communicate with their containing Web page.

Instructions

    • 1

      Insert <script type="text/javascript"></script> tags inside the head portion of your HTML document.

    • 2

      Type the following code inside the <script> tags you inserted in Step 1.

      function setStageSize (stageWidth, stageHeight): {

      var myMovie = document.getElementById("myMovie");

      myMovie.style.width = stageWidth + 'px';

      myMovie.style.height= stageHeight + 'px';

      }

    • 3

      Type the following code below the code from Step 2.

      ExternalInterface.call("setStageSize", "newStageWidth", "newStageHeight");

      Replace "newStageWidth" and "newStageHeight" with the desired width and height.

Related Searches:

References

Comments

Related Ads

Featured