How do I get the available browser width and height in Flex (not Flash)?
There is Capabilities.screenResolutionY and screenResolutionX that give the total monitor resolution and there is stage.stageWidth and stage.stageHeight but in the documentation it says "Calling the stageWidth property of a Stage object throws an exception for any caller that is not in the same security sandbox as the Stage owner (the main SWF file)". AND at times the stage property is null (how do you even get it on non-display objects like if you were in some random class?).
So how would I do this the Flex way and not throw errors (my application may be loaded by another at some point)?
~~ UPDATE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So I've been doing some testing and it looks like,
Rectangle(systemManager.getVisibleApplicationRect()).width
Rectangle(systemManager.getVisibleApplicationRect()).height
give me the information I need. These are even available at Application initialize.
Also,
systemManager.stage.stageWidth
systemManager.stage.stageHeight
give me the same information.
The systemManager is a property on the Application and every UIComponent so unless I'm in one of those classes (and I think in UIComponent's case it's a child of the Application) I still need to find a way to get to a reference to the systemManager in other types of classes.
~~ UPDATE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So freakazoid_em commented that I can use FlexGlobals.topLevelApplication to get the reference to the systemManager. With that I can get a reference to the visible browser width and height from anywhere in my Flex application (at anytime).
this.explicitHeight
andthis.explicitWidth
on your main application (Main.mxml) ? It should give you the width and height of your application when embedded in another html page - Majid LaissiFlexGlobals.topLevelApplication
. This property is set by the topmost Application object. - eddipedia