Code - Stage Size

The attached example will resize to fit the screen when the window in which the swf is running is resized.  Also resizes when the swf is run in a browser window.

Both a .fla and a .as are attached.
Here is the code from the .as file:

package {
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;

    public class StageExample extends Sprite {

        public function StageExample() {
            // EXACT_FIT expands your image to fit the current window size
            // don't need any event handlers to use this one.
            stage.scaleMode = StageScaleMode.EXACT_FIT;
           
            /* Uncomment to try the event handlers:
            // NO_SCALE is the default mode and Event.RESIZE fires
            // only if scaleMode == NO_SCALE
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            stage.addEventListener(Event.ACTIVATE, activateHandler);
            stage.addEventListener(Event.RESIZE, resizeHandler);
            */
        }

        private function activateHandler(event:Event):void {
            trace("activateHandler: " + event);
        }

        private function resizeHandler(event:Event):void {
            trace("resizeHandler: " + event);
            trace("stageWidth: " + stage.stageWidth + " stageHeight: " + stage.stageHeight);
        }
    }
}
Č
ċ
ď
StageExample.as
(1k)
Peter Nordquist,
May 10, 2011, 11:30 PM
ċ
ď
StageExample.fla
(9k)
Peter Nordquist,
May 10, 2011, 11:30 PM
Comments