Actionscript Flash

Greensock LoaderMax

As said in the previous post, Greensock also developped a loader, named LoaderMax, that makes loading external files to a flash application a piece of cake. Let’s see what we can make of it.

I’ll use the same flash demo I presented earlier, as it needs to load a series of images for a slide show as well as audio. The great feature of this loading system is that you can integrate subloaders to one main loader. There are, of course, many other awsome features like prioritizing, XML parsing, swf and video loading, but I don’t need them in this example. There’s no doubt I’ll be using them in the future though.

The first thing to do is declare an instance of LoaderMax intended as the main loader :

  • maxConnections is the number of simultaneous connections you would like during the loading process
  • onProgress defines an event handler when overall loading is in progress
  • onComplete is an event handler fired when the overall loader has finished loading
  • onChildProgress is like onProgress applied to each subloader
  • onChildComplete is like onComplete applied to each subloader
  • onError fires when loading fails

We’ll see how to deal with the event handlers later on.

For now, let’s concentrate on adding the subloaders :

As you can see, I loop through all my pictures and add an ImageLoader for each of them. I need a naming convention here, otherwise I’d probably have to go with an XML parser, but I’d have to update it if ever I added or changed the pictures. All I need here is to pass nbphotos via an external variable.

A movie clip is created to be used as a container recieving the uploaded picture. You’ll notice you can define the picture size, there’s more cool stuff you can do by just passing over parameters to the imageLoader, cropping and scaling come to mind. estimatedBytes allows you to give the loader an idea of the image weight before it actually gets the information, this is intended for loading progress accuracy.

The MP3Loader is pretty much the same, with specific features. autoPlay let’s the music start playing as soon as the loader has buffered enough data, whereas repeat is the number of the times it should repeat, -1 being forever. The great thing is you can then control the audio with the mp3Loader’s instance’s methods and properties, like musique.pauseSound(), musique.playSound(), or musique.volume=0.5

Once the subloaders are all added to the main loader, all you need to do is start the loading process.

Well, this is all well, but the interesting bit is to have the progress display on your screen. This is where the event handlers come in.

Without going into all the details, you can see how a progrees bar is easily scaled according to the loading progress. This works the same for the main loader and the subloaders. I use a counter which increments each time a subloader completes, so I know which image is currently loading, or if it’s the audio. I guess this isn’t very accurate, I should get this info directly from the event handler. What happens if one of the loader fails ? it beats me, I should test that sometime…

Anyway, here’s a screenshot of what it looks like, and here’s a link to the demo, so you can actually see it work 🙂


Just to finish off, I’d like to suggest this tutorial from Carl Schooff, one of GreenSock’s staff members, that really helped understand the basics of LoaderMax, not to mention he’s also been great help on the GreenSock forum, solving some of my issues.

This post has 2 comments

  1. This actually answered my drawback, thank you!

  2. kim tasker

    Not at all, I’m glad I could help !

Comments are closed.