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
Translate this post













































Leave your response!