WebLog!
Doing Windows, Filling Pockets And Reading Palms, Making Software That Works!
For Health, Home And Office

775.346.8185  •  skype: FutureWareSCG

Handling Multiple ActionScript Loader Errors

ActionScript’s LoaderInfo object is missing a lot of information if an error occurs. This presents a real housekeeping problem if multiple loads are done. Here’s a technique that makes sure nothing falls through the cracks.

Software development is easy when everything works right, but something always happens, and handling the what-ifs is a fundamental requirement to insure bomb proof reliability and undisturbed sleep at night. One of the things that can happen with some regularity is encountering problems when trying to load a remote resource, such as an image file. A server can go down, connections can be lost midstream, and 404 errors are a fact of file in the www.

The ActionScript Loader class works very well as long as everything else does, but the LoaderInfo error result is woefully incomplete if some housekeeping has to be done based on the failure. The housekeeping can be as simple as removing a rotating hourglass image or inserting an error message, such as ‘Image Not Available’, so that the visitor has an indication of what to do next.

Populating an image gallery is one case where this housekeeping is crucial. One of the wrinkles is that the loader events occur asynchronously and without any deterministic order. Here’s what we do to keep things clean and tidy.

The first thing is that each gallery item has a persistent object with ancillary properties, one of which is a boolean that indicates that the loader is completed, which is set to false when the object is created.

Next, a global counter is initially set to zero, incremented by one every time a loader is launched and decremented by one on every completion and error event.

When this counter hits zero during either decrement step, then the set of objects is scanned. Objects that do not have the loader completed flag set can then provide, through various properties, the related objects, sprites etc. that need to be processed for housekeeping, and then the loader completed flag is set.

© Copyright 2010 Chuck Brooks for FutureWare SCG

A Word From Our Sponser

Excel Excel When Importing FutureWare's SpreadsheetPowerImporter Spreadsheets Into Indesign, Pagemaker Or Quark!

Tags: , , ,

Comments are closed.