Question and Answer:

  Home  SWFObject

⟩ Do you have any idea why do stage.stageWidth and stage.stageHeight return 0 in Firefox or Internet Explorer when using dynamic publishing?

When using the dynamic publishing method in Internet Explorer or Firefox on Mac stage.stageWidth and stage.stageHeight might initially return 0 (note that for Internet Explorer the stage size will be available on first load, however when reloading or revisiting a page it will initially be 0).

The solution is to define a resize handler in your ActionScript code. The Flash Player team was obviously aware of this issue and therefore the Flash Player will keep on triggering the stage.resize event until it receives its actual width and height.

An AS3 example:

stage.addEventListener(Event.RESIZE, resizeHandler);

stage.dispatchEvent(new Event(Event.RESIZE)); // force stage resize event for normal cases

function resizeHandler(event:Event):void {

if (stage.stageHeight > 0 && stage.stageWidth > 0) {

stage.removeEventListener(Event.RESIZE, resizeHandler); // only execute once

// your initialization code here




More Questions for you: