Flash AS3 get window size

I want Flash to respond to the size of the browser window. What is wrong with this script? When I preview the swf The textfield ‘showWidth’ says ‘550’ even when I resize the window.

stage.addEventListener(Event.ENTER_FRAME, giveWidth)

function giveWidth(e:Event):void
{
var widthNR:Number = stage.stageWidth;
var widthStr:String = String(widthNR);
this.showWidth.text = widthStr;
}

change the scalemode, for example
stage.scaleMode=StageScaleMode.NO_SCALE;

you mentioned earlier you were publishing to android, you might be interested in

Capabilities.screenResolutionX;
Capabilities.screenResolutionY;

these will return the screen resolution, while stageWidth/height are going to show the swfs stage size.
with a stretched scalemode, you can have a stagewidth of one number, and resolution of another.

You’re on a roll tbo!

1 Like