May 5, 2009

How to trigger an event with ActionScript 3.0 when the sizes of a swf’s stage are modified

This is very useful when you try to create a “liquid” flash application.

ActionScript 3.0 code:

//The next 2 lines are not mandatory. //Use them if you whant to keep the original sizes. stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; // Other values: //TOP, BOTTOM, LEFT, RIGHT, TOP_RIGHT // BOTTOM_LEFT, BOTTOM_RIGHT stage.addEventListener(Event.RESIZE, resizeHandler); function resizeHandler(event:Event):void {         trace(stage.stageWidth);         trace(stage.stageHeight);         trace("An event has been triggered."); }