Goal: I want flash to have accurate information about the width and height of the browser viewport in device pixels when intializing, resizing, or on browser zoom events.
Specifics: I need to embed flash into an html page that runs in chrome, safari, firefox, ie. The swf must fill the entire browser viewport. I don’t want the flash to zoom. Inside of flash I can set StageScaleMode.NOSCALE so that flash renders to Device Pixels. I also set the state’s alignment to StageAlign.TOP_LEFT. Now all I need is the number of device pixels in the browser!
Problem: when there is a browser zoom or I open the site while the browser is zoomed, I cannot easily get information on the browser’s dimensions in device pixels.
Solution: acrobat.com’s online document editor (formerly known as buzzword) handles this problem just fine (free to play with with an account). What are they doing? In webkit browsers, they are able to keep the document.width to report device pixels every time. I am not sure what they are doing in firefox and ie.
What doesn’t work:
- Swffit does not support this.
- Just loading the swf into the browser is not a solution, as the swf needs to be embedded.
- This solution scales a swf to accomodate different browser zooms but does not get information on the browser window dimensions.
Solutions:
See selected answer below. Feedback welcome.
First a solution for webkit browsers only since it relies on
document.widthanddocument.height.Here is the html:
Here is the as3:
And here is a solution for IE, Mozilla, and Opera:
and the as3:
Finally, I believe there is a more optimal solution for Opera using screen.width and screen.height, but I’ve not tested it.