Home » ActionScript 3.0, Flash CS4, Flex, Javascript

Dynamic Stage resize + AS3

14 December 2009 2 Comments
Share on Facebook

Changing the size of flash document from Javascript will be handy in many situations like creating Flash widgets like

  • News scroller
  • Flash Banners

..

In this article we are going to create that effect.

First we need to import necessary classes.

import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.MovieClip;

The next step is to align the stage to TOP LEFT and scalemode to no scale.
Means we are aligning the stage to topleft even if we resize it and not scaling the contents on resize

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

The final step is to add Event listener for stage resize

stage.addEventListener(Event.RESIZE, handleResize);
function handleResize(e:Event):void
{
	//The resize code goes here
}

Note:
In the sample files I added code that creates a rectangle equal of stage size.

In Html, We are resizing the Flash using StageResize.width = Value.
Here,

StageResize is the name of the Flash movie create when publishing the Flash.

 onclick="StageResize.width = '150';StageResize.height =  '150';" href="#">Change W:150 X H:150

Download Source Files

GET THE UPDATES VIA EMAIL

We don't share your email anywhere, grab our rss via feedburner


2 Comments »

  • Boris said:

    Thanks a lot!!! Great!!! :D

  • Nick said:

    This is pretty cool, but is there a way to make the buttons inside as3 resize the flash stage, and subsequently resize the embedded object in html?

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.