views:

99

answers:

3

I know there are a lot of questions that have been asked about synchronicity in Flex, but I'm not sure if any cover the same issue I'm having. The title only refers to one possible solution I've been going for with this, but essentially here's my situation:

Say I have a Flex application, and I have an XML file with configuration settings I want loaded into that application, preferably at run-time (Although I would've been fine with compile-time as well but can't find a way to do this as the "-define" command-line parameter will only instantiate strings, numbers, and Booleans and I have some more complex configuration structures - I also cannot merely create these as a bunch of constants in Flex because they are used in numerous other places).

However, some of these configuration settings are also used in the various children of the application when they load, so there's no way to perform and complete the load before these containers are loaded (Because of asynchronicity - these children are loaded while the configuration is still being loaded in and parsed using an event listener and handler; of course, before the handler completes, the children components are already loaded incorrectly).

Is there any way to get this configuration file to load before the application's children do? Or even before the application itself? This approach of synchronizing the application load is only one possible approach, but no other approaches seem to fare any better.

+1  A: 

I have a 'shell' Application that doesn't have any UI children declared in its MXML. On its creationComplete handler, I load my configuration file. Once that load event is completed, I instantiate my children in Actionscript.

Mike Sickler
A: 

If those 'children' are not visible the the user, you can defer their initialization. So, after the config is loaded, trigger an event which then triggers the initalization of the children. This wouldn't imapair user perception.

Bozho
I've tried this approach also, changing the creationPolicy and then using createComponentsFromDescriptors, but it's still turning up errors in regards to descendants of those components not existing (Basically a ton of "Cannot access a property or method of a null object reference." errors) even though I'm calling createComponentsFromDescriptors(true) so as to create them recursively - the ones that aren't being instantiated are the ones that use config variables. I'm not sure if createComponentsFromDescriptors works in the way I'm imagining it does.
sage
Ok, what is the nature of those children? Are they service classes, are they UI objects?
Bozho
They are actually among both. One class of objects that ends up null is designed to handle mouse events and another, even more weird, is a data grid in one of the custom-made UI components. Because the lack of mouse handling, I can't yet tell if any other ones are broken yet.
sage
A: 

Similar to what Mike suggested, all you need to do is have a single Container (Canvas, VBox, etc) with creationPolicy="none"; when you are ready to initialize the application, you can call createComponentsFromDescriptors() on the Container.

Another approach would be put that content into a Module and load it after your configuration is loaded.

cliff.meyers
This is similar to the approach I've tried that seems to not be working. I set the application itself to have creationPolicy="none" and then try to call createComponentesFromDescriptors at the end of my event handler that parses the configuration file. But for whatever reason, it still doesn't instantiate all the children, even when I tell it to recursively. Certain components end up as null with little rhyme or reason as to why. I've tried the module approach with first loading config as a module and then the application, but the communication between the two didn't work out so well.
sage
This is probably because other child containers are inheriting the creationPolicy from the parent container. What if you use a ViewStack which has its first child as an empty Canvas and its second child as the main application view? Then after your configuration loads you can just set ViewStack.selectedIndex = 1 ?
cliff.meyers