1. 在IE中,主DisplayObject加入stage后,可能其大小还是0,这时可以通过监听resize信息,在主DisplayObject获得正确的大小后,运行主要程序。需要注意的是在这个过程中,可能会触发多次resize事件。
package
{
import flash.events.Event;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode; [SWF(width="400", height="300", frameRate="60", backgroundColor="#000000")]
public class Startup extends Sprite
{
public function Startup()
{
// These settings are recommended to avoid problems with touch handling
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT; if((stage.stageWidth != 0)&&(stage.stageHeight != 0)){
init();
} else {
//work around IE flash embedding issues
trace('stage is 0x0; listening for resize event');
stage.addEventListener(Event.RESIZE, onResize);
}
} private function onResize(e:Event):void
{
if((stage.stageWidth != 0)&&(stage.stageHeight != 0)){
stage.removeEventListener(Event.RESIZE, onResize);
MainProcess();
}
} private function MainProcess():void
{ }
}
}
参考