[Flashcoders] Wait for several things to be loaded
Hello, I am also building an AIR application for a simplified Learning Management System (LMS), using the MVC design pattern. The Web version of the training programs is available for preview on our web site. As far as loading several assets at the same time, I have developed a general preloader (Assets_Loader) which can handle several items at one-load. Once an item asset, like an XML, swf or image is loaded, the Assets_Loader stores it in the proper storage variable within the model. Off course, while maybe not essential for AIR application, this asset loader also measures the load progress of all the files as a percentage of all the files being loaded. If you are interested in exchanging more knowledge, and collaborate, feel free to contact me directly. D. Abramovich Interactive Training Solutions (ITS) 21911 Winnebago LN Lake Forest, CA 92630 USA Tel: 949.455.9921 Cel: 949.400.3010 _www.its-metacentre.com_ (http://www.its-metacentre.com/) In a message dated 3/18/2011 9:01:18 A.M. Pacific Daylight Time, flashcoders-requ...@chattyfig.figleaf.com writes: Subject: [Flashcoders] Wait for several things to be loaded To: Flash Coders List Message-ID: Content-Type: text/plain; charset="iso-8859-1" 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: ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Wait for several things to be loaded
There are many ways to accomplish this. As to what is better depends on the need of the application. If the view wholly dependent on multiple data parts arriving, I'll often work in sequence as quite often, I will have one part of data depending on another. For views that can display something, I'll bind a mediator to the data and once the data is loaded, the mediator will populate the view. jord On Mar 17, 2011, at 9:09 PM, 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? Jordan L. Chilcott Interactivity Unlimited / J & J Photography Guelph, Ontario - Tel: (519) 837-1879 Fax: (519) 837-8610 mailto:jchilc...@interactivityunlimited.com http://www.interactivityunlimited.com iChat/AIM: j1chilcott Skype: bear-faced-cow Author: "Building Web Sites with Macromedia Studio MX" Author: "Building Dynamic Web Sites with Macromedia Studio MX" Author: "Flash Professional 8: Training From the Source" Author: "Foundation Flash 8 Video" ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Wait for several things to be loaded
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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Wait for several things to be loaded
It does not look that bad. Since you know how many items have to be load, you may engage a counter: private function handleComplete(e:Event) { _loadCount++; if (_loadCount == 2) { dispatchEvent(new Event(Event.COMPLETE)); } } :-) Am 18.03.2011 02:09, schrieb Mattheis, Erik (MIN-WSW): 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] Wait for several things to be loaded
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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders