Can I get the obtain the size of the browser window in AS3?
The best method I\'ve found is to get the size with Javascript and send it to Flash as a FlashVar. One li
If you embedd your swf with height: 100%; width:100%
you could use stage.stageWidth
and stage.stageHeight
. If this is not the case you could implement a communication with JavaScript by using ExternalInterface
.
It depends if you are trying to set your swf to fullscreen, or simply obtain window dimensions for some other purpose.
If you are doing fullscreen, you need to set your stageScaleMode to NO_SCALE, and embed your flash object into a div that has its height and width parameters set to 100%. To deal with resizing, your flash project needs a resize event listener (applied to the stage), and all display objects need to respond to that resize listener. Once your swf is resizing properly, you can, as already noted, use stage.stageHeight / stageWidth to retrieve exact dimensions internally.
If, on the other hand, you just want to obtain the dimesions of the window, you will need to use ExternalInterface to make a javascript call. jQuery has some nice tools for quickly obtaining screen dimentions. Then its just a matter of sending that data back into flash. Remember that javascript has a resize event, as well, and that you can use it to force state changes in flash.
You're correct in the initial piece of the sequence - sending flashvars in on load, but to respond to screen size changes, you will need to apply one of these techniques.
Good luck