Question regarding preloading multiple .swfs

Hello all,

I’m currently working on a website whose sections exist in multiple external .swf files. I’m having a bit of trouble settling on a method for the loading these external sections.

The main .swf file contains the homepage for the site. It also will handle all the navigation and loading of the other sections. The current plan is to have the other sections loading in the background when the homepage(or any other loaded section) is displayed, so that (theoretically) while the user’s reading a section more content will be loading, and they won’t have to wait as long for the rest of the site to have loaded.

What I’ve done so far is set up an array of objects called SectionNodes. Each Section node contains the path to that section’s .swf, the DisplayObject for that actual section (if the section is loaded, the nav handling function places this on the stage), and a couple of flags to tell if the section is currently loading, or if it’s done loading (though honestly I could probably use a single state variable for this).

The preloading of the sections goes as follows: The array of SectionNodes is looped through. On the first SectionNode it encounters that is neither in the process of loading or already loaded, the loop breaks and a Loader object is instantiated, which loads that node’s .swf from the path specified in the node. An event listener is attached to the loader to tell when it’s complete.

On completion of the load, another function fires which pulls the .swf out of the loader, places it in the appropriate SectionNode, and then flags the SectionNode as done loading. Then, the preloading function is fired off again, it finds the next SectionNode that needs to be loaded, etc. When all sections have been loaded, the preloading function is no longer called (it will loop through all the nodes, not find any that need loading, and stop).

When the site is just sitting idle, given enough time the whole site will have loaded in the background. What is giving me a headache currently is what happens when a user starts navigating around.

The navigation currently works by finding the appropriate SectionNode in the array for the nav option clicked on. It then removes the current section from the stage and replaces it with the new one. If the section is currently in the process of loading, it will remove the current section, and then add a preloader clip to the stage, and tie it via event listener to the Loader object for that section. When the loader is done loading the section, it gets added to the stage.

My question is, what is going to happen if one section is currently loading either from clicking or from the background loading process, and a user clicks on another section that hasn’t loaded yet? My initial thought is that it should create a new Loader object for that section. However, I’m guessing that this isn’t a good idea because of browser connection limits. Even though the site only has 6 sections, I don’t think it would be a good idea to let it create a new Loader, since someone could still potentially go and click on all six sections instead of waiting for one to load. Disabling the nav through the whole loading process doesn’t seem very user-friendly to me, and may make it look like the site’s broken to users who are a bit impatient.

Would it be better to just use one Loader, and if it’s in the process of loading, just have it stop, dump it’s current content, and start loading the selected section? This seems kind of wasteful to me, but it would solve the connection limit problem. When the section is done loading, the section preloading function could fire off again to resume the background loading.

Another question I have is, if I’m flagging sections as done loading, what happens when the user clears their cache? Does the site lose all the sections it’s already loaded, or will they remain in memory since they’re being held in the array?

Is preloading content in the background more trouble than it’s worth? :puzzle:

Any thoughts on this are appreciated.