Home » ActionScript 3.0, Flash CS4, Flex, Javascript

Dynamic Stage resize + AS3

14 December 2009 No Comment

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

VN:F [1.7.7_1013]
Rating: 10.0/10 (2 votes cast)
VN:F [1.7.7_1013]
Rating: 0 (from 0 votes)
Dynamic Stage resize + AS310.0102
Translate this post
        
        
        
        
  

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.