Saturday, December 5, 2009

Beware of browser zoom and SWF dimensions...

The browser feature to zoom web pages in and out, causes the dimensions of the hosted SWF to be modified. For example; the object tag might state 640x480 and at 100% those are the values you will get. If a user zooms at 125% those values will change to 800x600.

CODE / HTML
StageScaleMode.NO_SCALE / scale: "noscale"

this.stage.stageWidth x this.stage.stageHeight

IE fires an extra StageResize event, the 2nd event fired contains the modified dimensions for your SWF. Also the 1st ENTER_FRAME event contains the modified dimensions. Any reference before either of these results to dimensions of zero.

Firefox and Chrome give you the modified values from the beginning but no resize event unless resized after SWF loaded.

CODE / HTML
StageScaleMode.EXACT_FIT / scale: "exactfit"
StageScaleMode.SHOW_ALL / scale: "showall"
StageScaleMode.NO_BORDER / scale: "noborder"

The RESIZE event does not happen with these scale modes.

In IE one must rely on the ENTER_FRAME event to get the modified dimensions.

Firefox and Chrome give you the modified values from the beginning.

Currently the only way to get the intended dimensions are to pass them as flash vars. One could also call an External Interface function to get those values too.