Error on adding FullScreenListener in creationComplete handler

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 in my Application. So i put that onto my creationComplete handler on the Application, i.e.

mx:Application xmlns:mx=”” width=”100%” height=”100%” creationComplete=”initStuff()”


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{
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…


2 Responses to Error on adding FullScreenListener in creationComplete handler

  1. Joan L says:

    It looks like some other people have run into this same problem. Here is the post:

    It looks like you should be able to the access the stage object after the updateComplete event or the applicationComplete event. I didn’t even know there was an applicationComplete event! Anyways, good luck!

  2. […] is null”. He suggests applicationComplete as a better event to use, as per Raghu’s post on a similar topic, and Wietse Veenstra’s helpful explanation of the order of Flex startup […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s