Flex 3: mx:Application.applicationComplete vs creationComplete

I’m working on a media player in Flex and I ran into an issue.

**Background**
When you click the “Fullscreen” button I change the label to “Exit Fullscreen” and vice versa when you click it again. If you use ESC key to return from fullscreen the label stays the same.

No problem right? I’ll add

bq. stage.addEventListener(FullScreenEvent.FULL_SCREEN, handleFullScreen);

to my _init()_ function which is called from the _creationComplete_ and I’m done, right?

**Problem**
“_creationComplete”_:http://livedocs.adobe.com/labs/flex3/langref/mx/core/UIComponent.html#event:creationComplete – “Dispatched when the component has finished its construction, property processing, measuring, layout, and drawing.”

Basically, when _creationComplete_ is called the _stage_ object is _null_. Huh? Yep, that’s right…it is null.

**Solution**
I found a “blog post by Raghu”:http://raghuonflex.wordpress.com/2007/03/06/error-on-adding-fullscreenlistener-in-creationcomplete-handler/ where he talked about using the SystemManager. That seems really hack’sh (which he felt the same as well). He then pointed out a “blog post by Wietse Veenstra”:http://www.wietseveenstra.nl/blog/2007/02/12/understanding-the-flex-application-startup-event-order/ which shows the start-up order.

Bottom line, _applicationComplete_ is the event we should use for init’ing our application. _creationComplete_ should be used for init’ing children of the application, if needed.

Hopefully this will help someone as it has helped me. God bless the blogosphere! ;-)

  • Popoburns

    Yo man! thanks for the tip! you’ve been a great help posting this info!

  • John C. Bland II

    No sweat man.

  • http://www.andreistoleru.com Andrei Stoleru

    Use “callLater”:
    creationComplete=”callLater(init)”
    ;)

  • John C. Bland II

    Yeah, but why? applicationComplete is what I use and suggest you use.

  • http://fusiongrokker.com Adam Tuttle

    Thanks! This post has helped me fix a problem that I’ve spent a full day trying to solve. I tried callLater from my CreationComplete event handler, but that didn’t work. Using the ApplicationComplete event fixed it.

    • http://www.johncblandii.com John C. Bland II

      Excellent. I’m glad it helped.

  • http://twitter.com/tusay @tusay

    had a similar problem, and got to your blog post!

  • Thiago

    Hey man…

    I am running into a similar issue. Let me explain. I have my Flex application a method which is called in the creationComplete event. Inside this method I have a HTTPService which is firstly invoked inside this method and the result is set to a var. After this I run a Alert.show(var) and this var is always null.

    Is this issue taking place because i am using creationComplete instead of applicationComplete?

    Many thanks

    • http://intensedebate.com/people/johncblandii johncblandii

      Sorry about the long delay here.

      Care to share any code?

      It sounds like either you're not setting the same var you're outputting or some other weirdness is happening.

  • Robert M.

    Man, if this works I’ll email you a kiss! Seriously, I am so p****d about a ‘bug’ I’ve been working on that hopefully this will work and solve a host of problems.

    • http://www.johncblandii.com johncblandii

      Sorry about the long delay in responding. Did it work?