Hi,

The "clunkiness" depends on how flexible you need to be I guess - to get it working, your approach is probably fine.

But, if you have to keep implementing it over and over again, you might want to start refining your approach.

e.g. If you have to add a data sets to be loaded, how do you accommodate this. When you have 10 or more, is is becoming unweildy and hard to manage? If so, it's probably time to refactor your approach to make it more flexible. Here is a couple of ideas off the top of my head - they are not "the right way", just ideas.

If you are using URLRequests to load data, you could separate out loading from your Database and SiteData and use something like QueueLoader: http://code.google.com/p/queueloader-as3/ or LoaderMax https://www.greensock.com/loadermax/ to load the data then populate your models.

You could create an interface that each of your Database, SiteData & other classes implement, then create an array of instances of these at runtime, then loop through them one by one, calling "init" on and setting flags / counting how many are loaded in your handler.

For more "complicated" systems that regularly talk to servers with lots of commands you may have to run in sequence, look up "asynchronous command chaining" in Google - this is probably beyond what you want to do here as you are only loading in data from several sources at startup by the look of it, but the approaches may give you ideas to help implement a flexible system.

    HTH

    Glen

On 18/03/2011 01:09, Mattheis, Erik (MIN-WSW) wrote:
I'm building an AIR app following the MVC pattern. Several parts of the model 
have to be loaded or created before the view can be initialized. I'm doing it 
like this - which works, but seems clunky. Is there a better way? From the main 
class of the model:

public function Model() {

   _database = new Database();
   _database.addEventListener(Event.COMPLETE, handleComplete);
   _database.init();

   _siteData = new SiteData();
   _siteData.addEventListener(Event.COMPLETE, handleComplete);
   _siteData.init();

  }

private function handleComplete(e:Event) {

   if (e.target is SiteData) {
      _siteDataLoaded = true;
   }
   else if (e.target is Database) {
     _databaseLoaded = true;
   }

    if (_siteDataLoaded&&  _databaseLoaded) {
      dispatchEvent(new Event(Event.COMPLETE));
   }

}

_ _ _
Erik Mattheis | Weber Shandwick
P: (952) 346.6610
M: (612) 377.2272
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to