Versatile content / media loader:

ActionScript 3 introduced new ways to load content and new types of content – now Flash can handle raw bytedata. This also increased the complexity of the process. You need a Loader, URLLoader, URLRequest, event listeners…

ContentLoader is a class that simplifies the process into a one class that can fulfill most of the basic needs:

– send and load data

– load bytedata

– load variables

– hande errors

– load images, mp3s, xml, text (JSON too, of course, but parsing is not supported)


 _loader = new ContentLoader();
 _loader.addEventListener(Event.COMPLETE, loader_INIT);
 _loader.addEventListener(ErrorEvent.ERROR, loader_ERROR);
 _loader.addEventListener(Event.INIT, loader_INIT);
 _loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, loader_HTTP_STATUS);

 //load different media (there are more)

 // finished
 //if it was an image
 //if it was text
 var text = _loader.content;

 //if it was variables
 var var = _loader.content.variable;

 // clear the loader
 _loader = null;

Download this class »