This is an issue i hit upon while i was doing the Full Screen App (
you can see it here). I wanted to add a listener to listen for the
FullScreenEvent (package
flash.events.FullScreenEvent) in my Application. So i put that onto my creationComplete handler on the Application, i.e.
mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" creationComplete="initStuff()"
and
private function initStuff():void{
stage.addEventListener(FullScreenEvent.FULL_SCREEN, handleFullScreen);
}
But, this threw a real time error (RTE) saying...
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at JustFullScreen/::initStuff()
at JustFullScreen/_Application1_creationComplete()
The above error means that the "
stage" object is null when it is trying to set the listener. What perplexes me is that if i put this
addListener code in a later part of the application, it works. Which means that the stage is getting intitialized between the
Application's creationComplete and the place in the code where i'm calling it. Is this a bug or does the stage get initialized later, dispatching a different event? I'm still digging.
Addendum (half hour later): I observed now that including the SystemManager class (
mx.managers.SystemManager) and then using the following code in the creationComplete handler works.
import mx.managers.SystemManager;
private function initStuff():void{
systemManager.stage.addEventListener(
FullScreenEvent.FULL_SCREEN, handleFullScreen);
}
So why is the systemManager object required if it is in the creationComplete handler and not if it is in a later part of the code... I'm confused now!!! Gotta tread back to the Flex Gurus :)
The code is here...
Addendum again (the next day) - Thanks Joan for the info. Thanks to her, i found the solution for the above problem...
It seems that the stage is available only after the updateComplete or applicationComplete Events. Read the post that demystified things for me...