views:

129

answers:

1

I am working on a small AIR desktop application and I have some configuration infos that I want to store in a little file that's loaded at some point when the application starts and will be used to set public properties on the root application object. This should work just as if I had public variables declared in an <mx:Script> block at the beginning of my main MXML file.

I seem to have the choice of three events that could be used to initiate loading the configuration file:

  • invoke
  • initialize
  • creationComplete

Did I overlook some more? Which one is appropriate and why? Does it matter at all?

Example issues that come to my mind are:

  • are all components already accessible or will I get NULL references?
  • will some of my settings be overwritten in a phase that's coming after the event?

There's probably more.

+5  A: 

If your handler needs to access UI components directly, you should wait for creationComplete; otherwise you'll get NULL references.

If you simply want to set properties on the root Application object, initialize seems the best place to do this. If you wait until creationComplete, and if the properties that you set are bound to your controls, then you might get a run-time resize or flicker as those components are updated.

Matt Dillard