Stage Display

stage.stageWidth VS stage.width - NOT THE SAME
Firstly to clarify a minor distinction that has baffled me before when it comes to discussing stage width.


 * stage.width is the width of content within the stage. When NOTHING is on the stage, stage.width would be 0.
 * stage.stageWidth is the width of the Flash Player

trace ("stage.width: "+stage.width); trace ("stage.stageWidth: "+stage.stageWidth);

Dynamically repositioning things when Flash player / window is resized
For this example, create a symbol on the stage called ball_mc. You can create a few more items as well so you can see the difference between objects that are going to be dynamically repositioned.

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

// ball_mc is going to be centred in the flash stage no matter how you resize it

function resizeStageHandler(evt:Event):void {	ball_mc.x = (ball_mc.stage.stageWidth / 2) - (ball_mc.width / 2); ball_mc.y = (ball_mc.stage.stageHeight / 2) - (ball_mc.height / 2); }

stage.addEventListener(Event.RESIZE, resizeStageHandler);

Tip:
 * For StageAlign, rather than TOP_LEFT - you can also try TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT. Alternatives can also be TOP, BOTTOM, LEFT, RIGHT (only specifying one alignment means that the object will only reposition itself on one axis.
 * For StageScaleMode, try replacing NO_SCALE with EXACT_FIT - these may cause content to get squished out of proportion. There is also SHOW_ALL, which will cause the above code to become useless. Try it and see what happens.

Full Screen mode
This is the AS3 method of making flash go fullscreen. Previously in AS2 you would call an fscommand to make it go fullscreen. Now in AS3, you can just change the stage's "displayState".

btnFullscreen.addEventListener(MouseEvent.CLICK, fullScreen);

function fullScreen(event:MouseEvent):void { stage.displayState=StageDisplayState.FULL_SCREEN; }

btnNormalscreen.addEventListener(MouseEvent.CLICK, normalScreen);

function normalScreen(event:MouseEvent):void { stage.displayState = StageDisplayState.NORMAL; } 

Quit / Close Window
Easiest way is still to use fscommand for closing the window. This only works when its a standalone app/exe or swf file. There is usually no reason to want to make a web browser close but if you needed to, then you will have to use javascript to handle the window closing function in the html file. We'll talk about that when we get around to doing dreamweaver and html5.

 fscommand("quit"); 