Changing Flash stage size from ActionScript

Changing the stage size can’t really be done in a pure sense just with AS, unfortunately.

It is always illegal to set the height property of the stage object, even if the calling object is the stage owner (the main SWF file).


That was from the help section in Flash CS3. So how do we get around this? Well with the help of jQuery Flash and ExternalInterface.call() we can fake it in some instances, my recent menu and banner combination is such an example and this piece is taken from that project.

In the ShockWave there is a test and a subsequent call to ExternalInterface.call() in order to resize the stage. Since the external call uses a JavaScript function let’s take a look at the JS we have in this case:

$(document).ready(function(){
  $("#menucont").flash(
    {
      src: 'menu.swf',
      width: '725',
      height: '297',
      wmode: 'transparent'
    },
    { expressInstall: true }
  );
});

function getCurPage(){
  return window.location.href;
}

function smallHeight(){
  $("#menucont").html('').flash(
    {
      src: 'menu_small.swf',
      width: '725',
      height: '100',
      wmode: 'transparent'
    },
    { expressInstall: true }
  );
}

The first document ready call loads the shockwave, getCurPage has been explained earlier.

Then the SWF will immediately check if a background image is to be loaded, if not it will use ExternalInterface.call(“smallHeight”) to reload itself. The reason is that since the background image won’t be loaded we don’t need the big height, it will look strange if a big part of the top of the page is completely empty.

Naturally the menu_small.swf file is not doing the above check, hence no infinite reloading can take place.

Note the wmode transparent setting, even though it’s not needed in my case I still use ‘transparent’. The reason is that when I didn’t set it the SWF area would briefly flash white on reload, highly annoying but it went away with the transparent setting.

Related Posts

Tags: , ,