Stage delays to initialize in IE browsers in as3



A very common issue that i have faced over last year is that codes related to stage object of the as3 document class seems to be null when application initializes in browser. This problem is noticeable only in the IE browsers. Note that flash player is a different version for IE Browsers and different for Mozilla / chore etc. IE handles activex controls in a different way than Mozilla etc browsers. It takes longer for flash player in IE to initialize its application stage. So how to resolve this ?

If you have a habit of using flashdevelop to create / mange your as3 projects ten you should have got it by now. If not don’t worry, here is the snippet :

public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
// you begin your code from here
}

Assuming that “Main” is your constructor of the document class, first the code checks to see if stage is initialized to something other than “null”. If yes we call the init function and put our code in it. If not, we add a listener for Event.ADDED_TO_STAGEВ .Hence if you try to use any stage related code before the application gets added to the top level , you will get “null” for the stage value. В As Adobe live docs suggest “Stage represents the entire area where Flash content is shown. The Stage object is not globally accessible. You need to access it through the stage property of a DisplayObject instance.” Thus your application is the top level display object. Once it gets added to the top level display area, it finds its stage (this.stage) .

Popularity: 3% [?]




October 12, 2009   Posted in: Actionscript 3.0, General

Leave a Reply