views:

103

answers:

1

I have a flex app that takes data from a back end database then displays the content in one of 3 views. These views are all in a viewstack which is instantiated in main.mxml The method to get the data (remote object)is also in main.mxml.

The views rely on the data so how can I go about making sure that the data is loaded first before any of the views in viewstack are created / initialised to stop me having null reference errors?

A: 

When you get the data, you should have a callback function defined to receive that data (callback function is the function you put into addEventListener). You just need to call the function to create your viewstack after all your callbacks have been called.

The way I would do it is create an class field called numCallbacks. Increment this variable everytime one of your callbacks is called. Right after you increment it, check if numCallbacks == the number of callbacks you have. If true, create your view stack.

teehoo
I have something that seems to work but could you tell me whether its a fluke or not. I have the entire viewstack in main set with a creation policy of NONE. In main i have a pre-initialization call the methods to get the data and a creation complete that calls initialize() on the viewstack.I know its a little sloppy and potentially hazardous but can you see any blatant pitfalls with this method?
Matt Robinson