LoaderMax – Smart AS3 Loading

  • Version: 1.921, Updated 2012-08-09
  • Compatibility: AS3 (Flash Player 9 or later)

LoaderMax is a new AS3 loading system that does for loading what TweenLite and TweenMax did for tweening, simplifying and enhancing the entire process. LoaderMax does much more than just get swf, mp3, css, video, image, text, binary, and xml files into your Flash application. It eats files for dinner, burps, and then asks for 2nds. And 3rds. Yet it’s surprisingly thin. In fact, it can be half the size of most other loading systems even though it delivers a surprising number of unique capabilities, some of which you probably never knew you needed but won’t want to live without. Here are a few of the noteworthy features:

  • Integrated subloaders – LoaderMax can recognize other LoaderMax-related loaders inside an asset being loaded and integrate them into the overall loading progress and the event model of the main loader. For example, if LoaderA subloads LoaderB which subloads LoaderC, LoaderA can report the entire group’s progress and not dispatch its COMPLETE event until LoaderB and LoaderC have finished loading (see the ASDocs about the “requireWithRoot” special property to enable this feature).
  • Flexible setup – build loaders in a variety of ways, including single-item loaders from nothing more than a URL (LoaderMax can automatically determine which type of loader to use based on the file extension) and loader queues automatically assembled from XML documents or an array of URLs.
  • Prioritize on the fly – build a queue that intelligently loads assets in the order specified but that can easily reprioritize any asset anytime. For example, if the user clicks something that requires loading immediately, just prioritize() its loader.
  • Tight file size – Many other systems are 16-24k+ even if you’re just loading text, but LoaderMax can be as little as 7k (depending on which loader types you use).
  • Detailed progress reporting – show progress of individual loaders or groups of loaders.
  • Robust event system – easily add event listeners, including multiple listeners in a single line of code. Events bubble up through LoaderMax hierarchies and carry a consistent target for easy identification.
  • Define an alternateURL for any loader – If the original url fails to load, it will automatically switch to the alternateURL and try again.
  • Avoid common Flash bugs/hassles – LoaderMax solves many problems like the recently discovered issues with subloading swfs that use TLF as well as garbage collection headaches with subloaded swfs, images, and NetStreams.
  • Pause and resume loads in progress
  • Conveniences galore – prevent asset caching, optionally manipulate many display characteristics like image smoothing, centering registration points, positioning, and many more. Set a width/height for an ImageLoader, SWFLoader, or VideoLoader and when it loads, the image/swf/video will automatically scale to fit using any of the following scaleModes: “stretch”, “proportionalInside”, “proportionalOutside”, “widthOnly”, or “heightOnly”. Even crop the asset inside that area with crop:true
  • Common set of properties and methods – all loaders types (XMLLoader, SWFLoader, ImageLoader, MP3Loader, CSSLoader, VideoLoader, LoaderMax, etc.) have name, status, loadTime, paused, bytesLoaded, bytesTotal, and progress properties as well as methods like load(), pause(), resume(), prioritize(), unload(), cancel(), auditSize() and dispose() delivering a touch of polymorphism sweetness.
  • Media playback controls in VideoLoader and MP3Loader – operationally control video and MP3 assets including methods that play, pause, and go to a specific time; properties that get or set volume, time, and duration; and events that monitor playback progress and more.
  • Automatic parsing of LoaderMax-related nodes inside XML – XMLLoader can look for LoaderMax-related nodes like <LoaderMax>, <ImageLoader>, <SWFLoader>, <XMLLoader>, <VideoLoader>, <DataLoader>, <CSSLoader>, <MP3Loader>, etc. inside XML files that it loads, and if any are found it can create the necessary instances and then begin loading any that had a load=”true” attribute, integrating them into the XMLLoader’s overall progress. See XMLLoader’s ASDocs for details.
  • Nest LoaderMax instances inside other LoaderMax instances as deeply as you want. – A LoaderMax instance is basically a queue of loaders which makes it simple to control or report their progress as a whole. You can put one queue into a slot inside another – group and nest them however you want. This makes complex queues simple.
  • Find loaders and content by name or url – Every loader has a name property which you can use to uniquely identify it. Feed a name or URL to the static LoaderMax.getLoader() or LoaderMax.getContent() methods to quickly get the associated loader or content from anywhere.
  • maxConnections – Set the maximum number of simultaneous connections for each LoaderMax instance (default is 2). This can speed up overall loading times.
  • Helper classes for code hinting and strict data typing – Check out the com.greensock.loading.data package for classes like LoaderMaxVars, ImageLoaderVars, XMLLoaderVars, etc.
  • Flex friendly – Simply change the LoaderMax.contentDisplayClass to FlexContentDisplay and then ImageLoaders, SWFLoaders, and VideoLoaders will return content wrapped in a UIComponent.

Interactive demo 1

Getting Started

Check out Rich Shupe’s “Meet LoaderMax” video series.

Documentation

Please view full ASDoc documentation here.

Tips & Tricks

Please see the dedicated tips & tricks page.

Sample AS3 code

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.*;
 
//create a LoaderMax named "mainQueue" and set up onProgress, onComplete and onError listeners
var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});

//append several loaders
queue.append( new XMLLoader("xml/data.xml", {name:"xmlDoc"}) );
queue.append( new ImageLoader("img/photo1.jpg", {name:"photo1", estimatedBytes:2400, container:this, alpha:0, width:250, height:150, scaleMode:"proportionalInside"}) );
queue.append( new SWFLoader("swf/child.swf", {name:"childClip", estimatedBytes:3000, container:this, x:250, autoPlay:false}) );
queue.append( new MP3Loader("mp3/audio.mp3", {name:"audio", repeat:2, autoPlay:true}) );

//prioritize the loader named "photo1"
LoaderMax.prioritize("photo1");  //same as LoaderMax.getLoader("photo1").prioritize();

//start loading
queue.load();
 
function progressHandler(event:LoaderEvent):void {
    trace("progress: " + event.target.progress);
}

function completeHandler(event:LoaderEvent):void {
    var image:ContentDisplay = LoaderMax.getContent("photo1");
    TweenLite.to(image, 1, {alpha:1, y:100});
    trace(event.target + " is complete!");
}
 
function errorHandler(event:LoaderEvent):void {
    trace("error occured with " + event.target + ": " + event.text);
}

Interactive demo 2

Avoid bugs, inconsistencies, and hassles

Reliability is a huge concern when it comes to loading external assets. Did you know there are a bunch of bugs, inconsistencies, and hassles in Adobe’s loading classes (Loader, URLLoader, NetStream, and Sound) that could cause trouble in your project? This is another reason why so many developers are shifting to LoaderMax – it works around these issues and provides a more stable, reliable, and robust foundation for loading. Use LoaderMax to avoid these issues:

  • Adobe’s Loader doesn’t properly subload swf files that use Adobe’s TLF. The preloading animation stays on the screen and the Loader’s “content” doesn’t refer to the real swf root, so reference errors are generated. See Adobe’s note here. See example here..
  • When MouseEvent listeners are added to swf content loaded by Adobe’s Loader, they are not dispatched properly (at least when the swf was published by CS5). See example here..
  • If close() is called on a Loader before its INIT event is dispatched, the content may not be properly unloaded or garbage collected.
  • If BitmapData.draw() is called on a partially-loaded child swf that contains a NetStream that hasn’t started yet, SECURITY_ERRORs are thrown.
  • If close() is called on an in-progress Loader, its bytesLoaded reports incorrectly on all subsequent loads even for completely different files. It cannot be reused effectively.
  • In certain browsers, a Loader or URLLoader’s bytesLoaded is occasionally reported as being greater than bytesTotal (impossible) when gzip is enabled on the server. This can lead to the progress never reaching 1.
  • Subloaded swf files may not be properly unloaded or garbage collected if all nested MovieClips aren’t stopped first and even if they are, the swf may not unload properly. It can be particularly problematic if the child swf has audio that’s attached to the timeline as a “stream”.
  • If pause() is called on a NetStream before the metaData is received (client.onMetaData() is called), it will never be received even after the NetStream resumes.
  • If Video.attachNetStream() is called when the NetStream’s buffer is full, the NetStream doesn’t attach properly (it doesn’t display). (See example FLA)
  • Video.attachNetStream() doesn’t work properly when called as the video is added to the display list with addChild() unless you seek() at the same time. That seek() cannot be to a time after the last encoded keyframe either or it won’t work. (See example FLA)
  • If NetStream.pause() is called when the NetStream isn’t attached to a Video object and the buffer isn’t full, it acts as though it continues playing (ignoring the pause() call).
  • If you publish your swf using Flash CS3 or CS4 and target Flash Player 9, NetStreams don’t reliably dispatch a “NetStream.Buffer.Full” NetStatusEvent for progressive downloads.
  • The Video object’s scrollRect won’t work properly unless the Video’s size is initially set to 320×160
  • If you seek() a NetStream to a position between the last keyframe and the end of the video, a NetStreamEvent with the info code “NetStream.Play.Stop” will be dispatched even if the NetStream is paused.
  • If you seek() a NetStream before it dispatches its first RENDER event, it will completely lose its audio.
  • NetStream only dispatches RENDER events when you publish to Flash Player 10 or later. For Flash Player 9, the only reliable way to know that it has rendered is to wait about 50ms.
  • If you call the Video object’s attachNetStream(null) method from within the RENDER event handler on the NetStream that was attached to it, Flash occasionally crashes (you can call it from pretty much anywhere else without a problem).
  • Sometimes a NetStream will dispatch a NetStatusEvent with a code of “NetStream.Play.Start” before the buffer has filled
  • As of Flash Player 11, if you call a NetStream’s seek() method on the same frame as when it finishes playback, it causes a flicker. This makes seamless looping…well…not seamless. You must wait a frame before doing the seek().
  • Unlike Loader, URLLoader, and Sound, there are no PROGRESS events dispatched by NetStream. To track its loading progress, you’d need to set up a Timer or ENTER_FRAME handler to keep checking the bytesLoaded and bytesTotal.
  • Even if you listen for the appropriate NetStatusEvent indicating that a NetStream is starting and pause() it immediately, you can often see the video briefly animate before it pauses and you can hear the audio briefly as well.
  • If you seek() to a certain time in a NetStream and then immediately check its “time” property, it is often incorrect (reflects the previous time, not the new one)
  • Sometimes a NetStream will report a “time” that is greater than its duration (which would be impossible of course). When it has finished playing, sometimes it reports a “time” that doesn’t match the duration either.
  • Occassionally Flash garbage collects a NetStream that’s attached to a Video and playing if two LocalConnections are connected with the same name.
  • There is a bug/inconsistency in Adobe’s NetStream class that causes relative URLs to use the swf’s location as the base path instead of the HTML page’s location like all other loaders. Therefore, it would be wise to use the “base” attribute of the <OBJECT> and <EMBED> tags in the HTML to make sure all relative paths are consistent. See http://kb2.adobe.com/cps/041/tn_04157.html for details.
  • A Sound object’s length doesn’t reflect its duration until it is completely loaded.
  • If close() is called on a Sound object, it no longer reports its bytesLoaded properly so it cannot be reused effectively.
  • Sometimes a SoundChannel’s position reports as being greater than the duration (should be impossible)
  • By default, images and swfs from other domains are loaded with heightened security restrictions that prevent bitmap smoothing, BitmapData captures, and script access in swfs.
  • If you add URLVariables to a URLRequest and set the URLRequest’s url to a String that has been modified using any of the String’s methods like split(), substr(), etc., in certain versions of the Flash Player (like 10.0.12.36) Flash will omit the “?” that separates the URL from the GET variables, causing invalid addresses.

FAQ

  1. Where do I get the code?
    LoaderMax is included in the main AS3 GreenSock download zip – just click the “Download AS3″ button at the top right corner of this page.
  2. What if I need to send variables to the server along with my request in a loader?
    The first parameter of the various loaders (ImageLoader, XMLLoader, SWFLoader, MP3Loader, etc.) accepts either a simple String URL or a URLRequest. So if you want to pass data to the server, simply construct a URLRequest accordingly, like:

    var request:URLRequest = new URLRequest("http://www.yourDomain.com/whatever.php");
    var data:URLVariables = new URLVariables();
    data.exampleSessionId = new Date().getTime();
    data.exampleUserLabel = "label1";
    request.data = data;
    request.method = URLRequestMethod.POST;
    var loader:ImageLoader = new ImageLoader(request, {name:"image1"});
  3. Do I need to define estimatedBytes for all my loaders?
    Nope. If you don’t define one, the default value of 20000 will be used. The only benefit of defining an estimatedBytes is to make the loader’s progress more accurate before it has downloaded enough information to determine the bytesTotal. Once it can accurately determine the bytesTotal, it will stop using the estimatedBytes. By default, when a LoaderMax loads, it will loop through its children first and find any that don’t explicitly define an “estimatedBytes” and quickly open a URLStream to determine the bytesTotal if possible. There’s a slight speed penalty when the LoaderMax first starts loading, but it makes it very accurate. You can turn that feature off with auditSize:false in your LoaderMax’s vars parameter.
  4. If a child loader inside a LoaderMax has already completed and I call load() again on the LoaderMax, will it waste time reloading that already-completed loader?
    No. If a loader has completed, LoaderMax will skip it in the queue for maximum efficiency and performance. If you want to force a full reload, though, set the “flush” parameter to true in your load() call, like myLoader.load(true)
  5. Why do I have to use different loader types (ImageLoader, XMLLoader, SWFLoader) instead of LoaderMax automatically figuring out the appropriate type based on the file extension in the URL?
    Actually, LoaderMax has a parse() method that can do exactly that (automatically figure out the appropriate loader type based on the file extension) – you just need to make sure you use LoaderMax.activate() first to activate the loader types that you want LoaderMax to be able to recognize like LoaderMax.activate([ImageLoader, SWFLoader]). This extra step may seem annoying, but there are a few reasons LoaderMax doesn’t activate all loader types by default:

    • Doing so would force ALL types of loaders to be compiled in your swf so that they’re available just in case you need them. Your project may never need an SWFLoader or MP3Loader, etc. but they would still be compiled into your SWF to accommodate “lazy” loading. In my opinion, this bloats the whole system which isn’t good because a loading system should be relatively lightweight in order to get things moving quickly.
    • It’s virtually impossible to accurately determine the file type if the extension is something like “.php” because you could have a server-side script that spits back any type – an image, an XML file, etc. In those cases, the “lazy” system would break down. You’d have to explicitly define the type anyway.

    Ultimately I believe it is much cleaner to have the developer choose the appropriate loader for the asset whenever possible and it definitely allows the system to be more lightweight and efficient. It could literally reduce the file size requirement by more than 60%.

  6. Is the LoaderMax API finalized? Might it change?
    This is a 1.0 release and while there are no plans to make any changes to the API, my experience has been that feedback from the community is invaluable and can help shape the API. I try to keep improving things to serve end users better, so don’t be surprised if there are some changes in upcoming months. I would recommend checking back frequently for updates or sign up for Club GreenSock so that you can be notified.
  7. Can I make suggestions for improving LoaderMax?
    Please do! Either in the comments section below or in the forums.
  8. Why did you use the loosely typed vars parameter to define all the special properties (like {name:”myLoader”, width:100, height:200}) instead of regular strong-typed parameters or properties? Your way doesn’t give me code hinting either.
    Don’t worry – you can get code hinting and strong data typing by using the data classes in the com.greensock.loading.data package, but two of the primary objectives were to keep file size to a minimum and encourage readable code, neither of which could be accomplished very well without using a generic vars object by default. There are quite a few optional special properties for various loaders (SWFLoader recognizes 41!) and regular constructor parameters just wouldn’t be feasible. Which one is more readable?:

    new SWFLoader("main.swf", "myFile", 100, 100, 200, 200, this, completeHandler, null, null, progressHandler);
    -OR-
    new SWFLoader("main.swf", {name:"myFile", x:100, y:100, width:200, height:200, container:this, onComplete:completeHandler, onProgress:progressHandler});

    But again, if you want strong typing and code hinting, use data classes in the com.greensock.loading.data package (like LoaderMaxVars, ImageLoaderVars, XMLLoaderVars, etc.) which allow you to define all your vars with a special object.

  9. Can I get the source code for the demos above?
    Sure, download it here.
  10. Is LoaderMax available in AS2? Will it be?
    The tweening platform and TransformManager, GreenSock’s 2 most popular products, ARE available in AS2 as well as AS3 but LoaderMax is only AS3 because…well…AS2 has been on the decline for a long time and LoaderMax relies heavily on the event system in AS3 so it would be a much bigger challenge to port it to AS2. Then there’s maintenance. Right now, every time I make an update to the AS3 version of TweenLite/Max/TimelineLite/Max/TransformManager, I must also make the update to the AS2 versions, copy all the files, create zips, post to the SVN, update the bonus zips for members, etc., Then there are language-specific differences I’d need to accommodate. So it just doesn’t seem worthwhile to do for a product like LoaderMax especially since AS2 is headed towards extinction.
  11. Will you be posting more examples?
    Yes.
  12. Do I have to purchase a license to use this code? Can I use it in commercial projects?
    You may use the code at no charge in commercial or non-commercial web sites, games, components, applications, and other software as long as end users are not charged a fee of any kind to use your product or gain access to it. If your client pays you a one-time fee to create the site/product, that’s perfectly fine and qualifies under the “no charge” license. If multiple end users are charged a usage/access/license fee of any kind, please simply sign up for a corporate Club GreenSock membership which comes with a special commercial license granting you permission to do so. Click here for details. Club GreenSock members get several useful bonus plugins, classes, update notifications, SVN access, and more. Please see the licensing page for details on licensing.

Need help?

Please post your question in the forums. You’ll increase your chances of getting a prompt answer if you provide a brief explanation and include a simplified FLA file (and any class files) that clearly demonstrates the problem.

Author: Jack Doyle
Copyright 2010, GreenSock (This work is subject to the terms here.)

  • Twitter
  • Facebook
  • Digg
  • StumbleUpon
  • del.icio.us
  • Yahoo! Buzz
  • Google Bookmarks
  • RSS
  • LinkedIn
  • Reddit

Comments (117) RSS

Posted by Elliot James Chong on June 16, 2010

I’m very excited to try the new library out Jack, loving the features you’ve included! Thank you for sharing!

Posted by Mark on June 16, 2010

GreenSock have done it again. My life just got a whole lot easier. Thank you!

Posted by Josh on June 16, 2010

Amazing work. Again. Thank you so much!

Posted by Steven on June 16, 2010

Ah, if only you released this 5 days ago! ;) Very nice work, I can’t wait to use it in my next project.

Posted by Dennis on June 16, 2010

Watching Rich demo it now. Thanks, Jack.

Posted by Ahrengot on June 16, 2010

I was one of the beta testers on this system, and have had some time to play aound with it on various projects. I truly recommend anyone dealing with web design/development to give it a go. It wil save you a huge load of time and trouble! (Sorry, couldn’t help the pun).

Posted by Ramiro Araujo on June 16, 2010

Congratulations! I’m already using it for production while it was beta :D, working like charm!

Posted by Mads Bjerre on June 16, 2010

You deserve a medal, Jack!

Posted by Elliot Geno on June 16, 2010

Wow that was close… I started down the road of creating my own, but I think I will use yours instead!

Posted by Teksetta on June 16, 2010

This is such a great utility and was built smartly. I’ve already started playing with it on multiple levels. Thank you so much!!

Posted by Marcelo Duende on June 16, 2010

Insane feature, it is a kind of bulkLoader, but very better. INSANE

Posted by Jay Wood on June 16, 2010

Great stuff (again). They should give out extremely shiny gold stars for this sort of thing. As ever, thanks for sharing all your hard work…

Posted by Urda on June 16, 2010

Again ? Jacks seal of quality: Small size and nestable. First TweenLite and now this ? Im a good Coder, but now i have inferiority complexes.
I hate you!

Posted by theHuston on June 16, 2010

Amazing. Many thanks.

Posted by theRemix on June 16, 2010

Awesome! Great work as usual guys!

Posted by Noah on June 16, 2010

Jack you are the man. This is so well done and sorely needed.

Posted by Nate Beck on June 16, 2010

Amazing job! Thanks for all of your hard work!

Posted by Fredrik on June 16, 2010

Fantastic work as always Mr. Green :o)

Posted by Arnie on June 16, 2010

Wow. Make that Wow!

Great, man.

Posted by sjimmisja on June 16, 2010

Frikkin awesome!! No more loading pains!!

Posted by Iván Gajate on June 16, 2010

Awesome!, I’m gonna play with it right now! ;

Posted by Paespedro on June 16, 2010

Very nice, I’ll take a look at it. Maybe this will be a good competitor for the also amazing Arthur Debert’s Bulk Loader (http://code.google.com/p/bulk-loader/).

Posted by teeeoooemmm on June 16, 2010

Saving dev lives left right and centre Jack Doyle – whoever you are! Thanks again!

Posted by Rod on June 16, 2010

Been using QueueLoader for most of my previous projects, really looking forward to playing with this though – centering the registration point and setting required w & h before its loaded, hell yeah!

Posted by Rod on June 16, 2010

There probably isn’t, but I’ll still ask – Is there any performance penalties in XMLLoader while it checks for LoaderMax specific tag names? And if so, can we disable this?

Posted by Rod on June 16, 2010

Silly me – integrateProgress = false to disable XMLLoader looking for LoaderMax related nodes :)

Posted by David C on June 16, 2010

Haven’t had a chance to work with LoaderMax yet, but just cos it’s from GreenSock I know I’m gonna love it!

Posted by Paespedro on June 16, 2010

Well, after a little look at the LoaderMax i can say that it IS better than the BulkLoader in a lot of ways. It’s like a future version of it for me, plus lots of extras like you always do.

Posted by Mario on June 16, 2010

This is going to be a huge hit! You’re doing so much good to the community, Jack. You the man! Adobe should thank you personally and offer a partnership or something!

Posted by lordB8r on June 16, 2010

I love that it can eat seconds, then thirds, and still stay slim! Loving it. Thanks for the lib – looking forward to using it as much as possible.

Posted by Justin Bernard on June 16, 2010

rocking again, jack!

Posted by turtlebite on June 16, 2010

This is awesome! I will definitly integrate it in the next release of the Fleb Framework (www.flebframework.com)!

Posted by Tim on June 16, 2010

Best work, as usual!
Thanks Jack! I already used it while it was beta.

Keep up the great work and make our life easier!

Posted by Ocho Durando on June 16, 2010

Fantastic Library!
Great job Jack!

Posted by Dourado on June 17, 2010

Many projects especially those like micro/publicity web apps require all time loads so loads are in some cases my first concern. That’s why I have been working with bulkLoader for a while and I use a class that manage all the load’s that my app requires thru bulkloader and XML.

Now you create this…wow.. it’s like “listening” my methods!? :)
Great job Jack!

Posted by Sébastien on June 17, 2010

Nice class ! Very usefull. I will use it in my next projects, for sure. Thanks for sharing ;)

Posted by activetofocus on June 17, 2010

Great tools.I like it.

Posted by Christian on June 17, 2010

How can I cast a loaded SWF to a custom datatype (like a baseclass or Interface)

Get rumtime errors when I try…

Posted by Christian on June 17, 2010

Got it! This is how:

var myLoadedSWF : MyCustomDataType;

myLoadedSWF = SWFLoader.rawContent as MyCustomDataType;
addChild(_module as DisplayObject);

Posted by Adam Jackett on June 17, 2010

I wrote my own class a couple weeks ago – MultiLoader… what a waste of time because this kicks my loader’s @$$. I’m proud to be a shockingly green member. Thanks for making my life so much easier.

Posted by Joshua Ben on June 17, 2010

Once again you guys have rocked it. This is exciting, and I am going to start a new project just as a study in LoaderMax.
Thanks

Posted by grabek on June 17, 2010

About Freakn’ time dude!!! I remember a time about a year ago when I asked if you were going to create this. And now you have!

Super awesome job! Best script ever ;)

Posted by Randall W. Haws on June 17, 2010

Brilliant. Magic.

Posted by Brandon on June 18, 2010

I’ve been wishing and hoping GreenSock would do this for years! I’m so absolutely excited and happy, it raises suspicion.

Awesome! Thank you!

-B

Posted by tamt on June 22, 2010

thanks for sharing~~

Posted by Adam on June 22, 2010

Awesome! This looks like an awesome preloading class… I can wait to try it out. Thanks for sharing!

Posted by Peter_D on June 24, 2010

Fantastic work…as always ;)

Posted by mdac on June 26, 2010

Well… If I needed a kick up the backside to finally switch to as3, then this is it.

Ok jack you’ve finally convinced me.

Fine work.

Posted by jrams623 on June 27, 2010

Thanks for this amazing utility! I’ve been able to overhaul my entire workflow.

Posted by Tim on June 30, 2010

This is so awesome, thanks for your efforts!

Feature request: DownloaderMax – Ability to queue up files like this for physical download to local machine with directory structure. Would be absolutely perfect for offline AIR apps that depend on externally loaded content.

Posted by Sébastien on July 2, 2010

Very nice loader solution ;) Thanks a lot for sharing this !

Posted by leef on July 3, 2010

This is great! I’ve built several loaders overtime, usually in response to a project’s need, and each time have improved on reusability, and features, but haven’t taken it this far. Thanks!!!

Posted by Joisiney Leandro on July 9, 2010

Is it possible to pass a parameter to the onComplete handler. Kinda like:

_swfLoader = new SWFLoader(“child.swf”, {parameters:["josé", "joão"], onComplete:_completeHandler});

function _completeHandler(event:LoaderEvent):void {
trace(event.target.parameters);
}

Posted by Kaleb Wyman on July 9, 2010

This is brilliant. Kudos, Jack.

Posted by Jack on July 9, 2010

Sure, you can use the vars object to store your data, like this:

_swfLoader = new SWFLoader(“child.swf”, {parameters:["josé", "joão"], onComplete:_completeHandler});

function _completeHandler(event:LoaderEvent):void {
trace(event.target.vars.parameters);
}

Posted by Fernando Checa on July 12, 2010

Hi,

Could you access events in loaderMax?

I would like to know when an element has loaded but not with an onComplete function.

I would like to add an event listener to do that.
Listen to events and take actions based on that.

Thanks

Posted by Jack on July 12, 2010

Absolutely, Farnando – LoaderMax is fully compatible with the standard addEventListener() way of working in AS3. The various special properties like onComplete, onProgress, onFail, etc. are simply shortcuts that allow you do set up all those listeners in one fell swoop. It shortens the amount of code you need to write, but feel free to do stuff like this if you prefer:

loader.addEventListener(LoaderEvent.COMPLETE, completeHandler);

Posted by swfninja on July 13, 2010

Jack, you never cease to amaze!

Posted by Fernando Checa on July 15, 2010

How are files loaded?
If I add 3 images to the queue, do they start to load all at the same time?
I ask because I would like to be able to load sequentially. One file at a time. Is that possible?
Or do I have to load one file, wait until it’s finished loading and then add the next one to the loader?

Posted by Jack on July 15, 2010

LoaderMax gives you complete control over how your queue loads. There’s a maxConnections property that controls how many files it will try to load simultaneously (the default value is 2 which provides a nice mix of prioritization and speed). If you set maxConnections to 1, it will load one file at a time, but loading things sequentially like that is slightly slower because it doesn’t allow Flash to leverage multiple streams at the same time. In other words, if maxConnections is 2 instead of 1, it will finish the overall load of the entire queue a bit faster because it can make better use of your connection.

If you want things to load sequentially one-after-the-other, just set maxConnections to 1, dump all your loaders into the LoaderMax, and let ‘er rip. LoaderMax will handle everything for you.

Posted by Mike Donnelly on July 28, 2010

Jack, thank you so much! You get the high score for karma points, helping out so many embattled coders with such *total* quality software!! What on earth will you do next?

Posted by mlemonro on July 28, 2010

There is some changelog for this module? New version came out, so it would be nice to see what’s new or whats changed in this release without using diff on the source code..

Posted by Jack on July 28, 2010

mlemonro, yep, there’s a changelog.txt file in the com/greensock/loading directory.

Posted by Zync on August 1, 2010

Loving loaderMax, works soo well and no hiccups. Would love to see an appendURLs method added. That way our array of files could be just the filename without the extension repeating (eg. .jpg). Guess it would only be useful for gallery’s but every bit of text saving counts :D

var aImages:Array = new Array(“image1″,”image2″); //etc

instead of

var aImages:Array = new Array(“image1.jpg”,”image2.jpg”); //etc

Posted by iguoguo on August 14, 2010

very good framework.
I must spend much time to learn it.
Thank you .

Posted by Bruno on August 14, 2010

You are the man! Thanks a lot again!!!

Posted by Paras Sheth on August 17, 2010

well green this is!

Posted by Zach Zurn on August 17, 2010

Thank you so much for all of your classes. They are extremely well written and easy to use.

I can’t find one project where I won’t use your classes all over the place.

Posted by Benjiman on August 19, 2010

Excellent,good job ……I am enjoying your loader~~

Posted by Cameron Kingzett on August 19, 2010

Ridiculously good. Jack takes everything up a level with his tools, and yet somehow makes it simpler as well.

The control and depth of event management for loading is great, the documentation is excellent, the file size trumps all others, and now I get to have my loader, and my tweener living happily under one roof.

Leave your other bloat-loaders behind!

Posted by ason0356224 on September 14, 2010

hi Jack.

If I pause the LoaderMAX(only one SelfLoader).
Whether the “main.swf” stop loading? or do nothing?

Posted by Jack on September 14, 2010

ason0, the only purpose of a SelfLoader is to report the loading progress of the main swf, so if you pause() a SelfLoader, it doesn’t actually stop the loading of the swf because…well…that would be impossible.

Posted by Shaun on September 15, 2010

Well, this is definatly a ‘load’ off my mine…

Posted by Natán on September 15, 2010

Hi Jack,

Quick question (hope I’m not missing the answer or it’s obvious).

What if I want to reuse already-loaded bytes of an image? I could access the loader.content property, right? But… what if I want another loader object? If I try to load an image that was already loaded earlier, is LoaderMax smart enough to “recycle” the already-loaded bytes, or will it make another server call (even if it does use the cache)?

Thanks for your time.

Posted by Jack on September 15, 2010

Natán, sure, if you want to make a copy of an image that you loaded, you could do:

var image:Bitmap = new Bitmap(loader.rawContent.bitmapData);

As far as LoaderMax being “smart” enough to recycle, that’s a tricky question. It assumes that the “smart” thing to do would be to always recycle but I don’t think that’s the case. Imagine loading a swf, allowing it to play, and then wanting to create a duplicate swf that plays next to it and starts all over again. In that case, it wouldn’t be smart at all to just hand over that already loaded swf. It would be partially played and you can’t really duplicate a swf anyway (assets, state, variables, etc.). It would need to get loaded again as a separate instance. For images it might sound “smart” to reuse data, but again that may not be the case – what if your ImageLoader hits a php script that spits back a new image each time you make the request and noCache is set to true?

In general, I try to make things as “smart” as possible, but I don’t like making too many assumptions about what the developer wants to do because it can limit flexibility. I prefer to give them the tools to get what they need out of a clean API. If a loader is already loaded and you call load(), it will not waste resources forcing a reload (although you can do that with the flush parameter). It will automatically skip over failed, paused, and loaded loaders as it rips through its queue. That’s the “smart” part, but if you create a separate loader instance that has the same URL as a previous one, it doesn’t force it to use the previously loaded data. It respects the developer’s request to have a separate, distinct instance with fresh data.

Posted by Girish on September 17, 2010

is loadermax free or a part of club membership?

Posted by Jack on September 17, 2010

Yes, Girish, LoaderMax is completely free to use in almost all types of commercial and non-commercial sites/products although there is a very rare, particular type of usage that requires the special license that comes with corporate Club GreenSock memberships. See http://www.greensock.com/licensing/ for details. All of the LoaderMax files are in the free download on http://www.LoaderMax.com, so you don’t need to pay anything to get the files.

Posted by Stefan on September 29, 2010

Good morning, Jack.
Is it possible to add dynamic cuePoints to the videoLoader? Like the “addASCuePoint()” method from the FLVPlayback Component. Thank you for the great work.

Posted by Jim B on September 29, 2010

I’ve used and loved BulkLoader for many years now. Its extremely powerful. But one of things I wasn’t crazy about(in additon to the bloated file size) was the need to always daisy chain my loaders, first loading my config XML, grabing asset path information, and THEN actually preloading my assets.

With the new intelligent autoload feature of the XMLLoader class this is no longer necessary.
Fantastic work Jack!

Posted by Jack on September 29, 2010

Your wish is my command, Stefan. I just posted an update to VideoLoader (1.6) and it now has addASCuePoint() and removeASCuePoint() methods. Enjoy!

Posted by Stefan on October 1, 2010

Jack! You are the best! Thank you so much!

Posted by marc on October 8, 2010

Just amazing, i test it for 5 minutes.. i will never use anything else!

Posted by Nitin Mukesh on October 11, 2010

Do I need to buy this class for commercial project or is it free to use in any type of project?

Posted by Jack on October 11, 2010

Nitin, LoaderMax is completely free for MOST commercial projects. There is a very particular type of commercial usage that requires the special license that comes with corporate Club GreenSock memberships. See http://www.greensock.com/licensing/ for details.

Posted by marcT on October 27, 2010

Great Engine! Great job!
Just debugged my App because the SelfLoader didnt fire when used after the swf was already loaded. So thanks for your update on Oct 13 for that! Had this problem already in 2 projects, so it’s not a so unlikely phenomenon.
Thanks very very much for your great work, i’ll go ahead to be a really green socked club member! :D

Posted by Pablo on November 2, 2010

Making my life easier, thanks!

Posted by isnow on November 19, 2010

How could I Know the LoaderMax is Loading now?

Posted by Jack on November 19, 2010

isnow, every loader (and LoaderMax queue) has a “progress” property that reaches 1 when it is finished loading. Each loader also has a “status” property that you can check.

Posted by Marcelo on November 20, 2010

Yo Jack, what if I want to download my SWF assets and after get this asset in my library? I can’t find the “e.target.content.loaderInfo.applicationDomain.getDefinition(“preloader_mushroom”) as Class”

If you have any idea, please tell me.

Posted by Jack on November 20, 2010

Marcelo, SWFLoader makes that very simple actually:

myLoader.getClass(“preloader_mushroom”);

See the getClass() method in the ASDocs for a full description.

Posted by Marek Karwowski on November 22, 2010

Promising! Well done greensock!

Posted by Jakub Słaby on January 4, 2011

Great engine, only one thing is still bugging me. The ContentDisplay Class. Basically, what if I’m loading a SWF or an Image and I dont want it to be placed in a ContentDisplay sprite?

I’ve already tried to modify the DisplayObjectLoader but I would like not to do that. Is is possible not to create the ContentDIsplay object?

Posted by Jack on January 4, 2011

Jakub, I originally built LoaderMax so without any ContentDisplay class, but it quickly became apparent that one would be necessary (well, extremely convenient at least). A lot of people requested it. ContentDisplay solves all sorts of problems, as described in the docs. But if you don’t want to use it, you are certainly welcome to reparent the rawContent (your subloaded swf in this case) to wherever you want and then dispose() the SWFLoader when you’re done.

Is there some reason you’d need to avoid a ContentDisplay ever even being created in the first place? It uses very little memory and I cannot imagine you’d EVER see even the slightest performance degradation.

Posted by Ernest on January 17, 2011

Jack you are absolutely AMAZING. Thanks for great stuff and best luck :)

Posted by drunkcat on February 14, 2011

How to use .parse() with binary file/files?
For example, LoaderMax.parse( “test.zip” ) throws an error “LoaderMax could not parse (…)”

Posted by Jack on February 15, 2011

Sure, drunkcat, I just uploaded a new version that adds a BinaryDataLoader class. Just activate() that and then LoaderMax.parse() will associate zip files with BinaryDataLoader. In the new version of LoaderMax, you can also LoaderMax.registerFileType() to add other types, like .pdf or whatever.

Posted by hadro on March 17, 2011

This is amazing! I’ve used it on my two last projects. It works perfectly. I like the class activator and Vars chain the most :) brilliant idea! I love my code being clean, so strongly typed props are exactly what I desired.

Posted by toer on March 29, 2011

my images loaded with loadermax are blurry. can you tell me why this is happening?

Posted by Jack on March 30, 2011

LoaderMax will not affect the image itself at all, but if you defined a width and/or height, it will scale the image to that size. Whenever you scale an image in Flash, you risk having blurry pixels (like in any program) because if the resolution isn’t adequate, things get fuzzy. For example, if you load a 100×100 image and scale it to fit into a 500×500 area, the pixels get 5 times bigger and get blurred a bit (since smoothing is turned on by default). You can set smoothing:false if you want. And make sure your image has adequate resolution. Oh, and if you apply any 3D properties (like rotationX, rotationY, rotationZ, or z), Flash applies a matrix3D which tends to make things a bit blurry, but that has nothing to do with LoaderMax.

Posted by Matt on April 8, 2011

Hey Jack,

I came here to post a question and noticed your response above regarding the 3D properties. I’ve found this over at Flash and Math – http://www.flashandmath.com/flashcs4/blursol/index.html. If you just drop on image on the stage their solution works when trying a 3D rotation.

I’ve been playing around with different parameters of LoaderMax to try and achieve the same result, but I can’t seem to manage it. Would you know of any combination of parameter settings that might allow for this?

Posted by Jack on April 13, 2011

Matt, you’re welcome to listen for the INIT or COMPLETE event on the ImageLoader and then apply the custom scaleX/scaleY as that article recommended to help eliminate the 3D blur at z of 0, but I don’t think it would be appropriate to do that automatically inside ImageLoader because it could be confusing for developers. And most of the time when 3D properties are set, they’re not left at the default values of 0 anyway.

Posted by Matt on April 23, 2011

Perfect. I’m going to give that a whirl. I actually just came back to have a look at your ASDocs and saw that you had replied. I appreciate the response.

BTW – if I ever end up winning the lottery or somehow acquiring loads of cash I’m giving you a $1 million right off the top. Your work is invaluable. Can’t thank you enough.

Posted by Louie on June 20, 2011

This is a great website and a great help for designers and non-programmers like me. I hope this website won’t go offline the next 10 years… :-)

Posted by cronoklee on October 16, 2011

Adobe should really built your classes into the CS packages. As3 is so damn convoluted sometimes.
Thanks for making the world easier!

Posted by upiru on January 13, 2012

Hi thanks for all these neat libs, lot of saved time !

Posted by amene on January 14, 2012

thanks so much for your perfect work.

Posted by Qusai Tabbal on February 25, 2012

Thanks for these valuable stuff , you are FlashMasters .. love you :)

Posted by Juni on April 4, 2012

Hello, I just want to say thanks. You saved me from those bugs I`ve encountered all over again. I will start my next project and use all of your products, and thank you for having a great and “free” versions…thank you.

Posted by Gite Huber on August 27, 2012

Hello,
LoaderMax is perfect, too!
But is there a maximum of images, LoaderMax can handle?
Between 1350 and 1373 the Loading stops…
Thanks for help,
Gite.

Posted by Jack on August 27, 2012

Gite, LoaderMax itself has no limit, no, but the Flash Player does. It depends on the system, memory, etc. I definitely wouldn’t recommend loading over
1000 images and having them all in memory at the same time, no. That’s pushing the Flash Player too far. Again, that’s not a limitation of LoaderMax – it’s just the Flash Player. You can preload all the images and unload() the ones you don’t need immediately so that they’re at least in the browser cache and can be loaded very quickly when you need them.

Posted by John on November 28, 2012

Hey guys,

I’ve used LoaderMax on a number of projects it’s amazing so first off thanks so much! Hopefully without sounding too greedy I’m wondering if you guys have any plans for a JS loading platform?

Again thanks so much!

John

Posted by Jack on November 28, 2012

Thanks for asking, John. We don’t have any immediate plans to create a JavaScript loading platform yet, but it may eventually happen. Right now what’s needed most in the industry is a solid animation platform and we’re very focused on filling that need. You’re not the first to ask about the JS loading platform, by the way, and we’re taking notice of what the community is asking for. It matters to us and helps shape what we pursue.

Posted by Jairus on December 17, 2012

kudos on all these AS3 libraries, you have made my life as a developer soooooooo much easier.

Posted by Anton on December 28, 2012

Hello!

Thanks for all the libs! I use Tween[Max|Lite] and LoaderMax.

I use LoaderMax to load MP3 in my application. The server returning MP3 sets huge expiration time in HTTP headers to ensure that MP3 is cached by browser. But when I run the app and view its requests I see that there are still actual requests to server. And more than that, LoaderMax explicitly adds gsCacheBusterID query parameter (=timestamp) preventing browser cache to hit.

Do these requests download entire file? This might burn me few TB a day ;)

Thanks.

Posted by Jack on December 28, 2012

Anton, the request with the gsCacheBusterID at the end is just a very quick URLStream load that only loads enough to figure out the total size of the file (typically as soon as a single small chunk is sent by the server, it tells LoaderMax what it needs and LoaderMax kills the connection immediately). This is necessary for LoaderMax to accurately report the progress of entire queues of files, but you can easily turn off the file size auditing feature if you prefer. See tips 8 through 10 here: http://www.greensock.com/loadermax-tips/#8

Posted by marcum on January 6, 2013

My question concerns loaderMax object with maxconnections set to 5. When running via Adobe Air 3.5 in iOS the loading of images is super fast. However today I ported my app to an Android tablet and it’s VERY slow (seems like maxconnections never gets above 1). Just curious if anyone had the same problem. Thanks

Posted by Jack on January 6, 2013

Marcum, each ecosystem imposes its own limitations on connections which LoaderMax cannot override. For example, some browsers may only allow a maximum of 3 simultaneous connections. Some may allow 5. Android may allow only 1. When you set a maxConnections value in LoaderMax, it’s just an upper limit – that doesn’t mean it will be able to hit that maximum.

To download the code, you must agree to the following license:

"NO CHARGE" NON-EXCLUSIVE SOFTWARE LICENSE AGREEMENT
-----------------------------------------------------------------------------
PLAIN ENGLISH SUMMARY:

  1. You may use the code at no charge in commercial or non-commercial apps, web sites, games, components, and other software as long as end users are not charged a fee of any kind to use your product or gain access to any part of it. If your client pays you a one-time fee to create the site/product, that's perfectly fine and qualifies under the "no charge" license. If end users are charged a usage/access/license fee, please sign up for a "Business Green" Club GreenSock membership which comes with a comprehensive commercial license. See http://www.greensock.com/club/ for details.
  2. Use at your own risk. No warranties are offered.
  3. Please respect the copyright.

-----------------------------------------------------------------------------

LEGALESE:

This is a legal agreement between you (either an individual or a single entity) and GreenSock, Inc. ("GREENSOCK") for the proprietary GreenSock code known as TweenLite, TweenMax, TweenNano, TimelineLite, TimelineMax, and other copyrighted code that is available for download at http://www.greensock.com (this code and documentation, as well as any updates which may at GREENSOCK's sole discretion be provided to you from time to time, are referred to in this Agreement as "PROGRAM"). By downloading, copying, or otherwise using the PROGRAM, you agree to the terms and conditions of this Agreement. If you do not agree to the terms and conditions of this Agreement, please do not download or use the PROGRAM.

I. LICENSE
A. Subject to the terms and conditions of this Agreement, GREENSOCK hereby grants you a non-exclusive, worldwide, non-transferable right to use the PROGRAM in apps, web sites, games, components and other software applications ("Developed Works") for which the end user is NOT charged any fees. If you would like to use the code in a commercially licensed Developed Work for which end users are charged a fee (either for usage or access), simply sign up for the appropriate "Business Green" Club GreenSock membership at http://www.greensock.com/club/.

II. LIMITATION OF LICENSE AND RESTRICTIONS
A. You agree that you will not sell, rent, or license the PROGRAM's source code or any derivative works thereof to any third party without the prior written consent of GREENSOCK. Distribution of the PROGRAM as part of your Developed Work is acceptable so long as it is used exclusively as a part of your Developed Work. You agree not to modify or delete GREENSOCK'S existing copyright notices located in the source code.

B. You may use, duplicate, and distribute the compiled object code as embedded in Developed Works created by you, either for your own use or for distribution to a third party so long as end users of the Developed Work are not charged a fee for usage of or access to any portion of the Developed Work. Please see http://www.greensock.com/licensing/ for descriptions of Developed Works that qualify for the "No Charge" license.

C. You may make modifications to the source code exclusively for your own use in order to perform bug fixes or other minor edits required to operate the PROGRAM as originally intended.

III. CONSIDERATION
A. The license rights granted to you under this Agreement are at no charge, but only in the following circumstances: If on your own behalf or on behalf of a third party you incorporate the PROGRAM into a web site, app, game, program or any component thereof (collectively, "Developed Work"), which in the case of a web site, must be accessible to internet users without payment of a fee of any kind, and in the case of a software application, game, program or component, neither you nor anyone to whom you distribute the Developed Work charges a user a fee of any kind to use such Developed Work or application, game, program or component into which such Developed Work is embedded. The foregoing shall apply regardless of whether you are paid to create such Developed Work.

B. In the event your intended use of the PROGRAM does not meet the criteria for the "no charge" license rights set forth in the immediately preceding paragraph, then you are not licensed to use the PROGRAM under this Agreement and must license the PROGRAM under GREENSOCK'S separate fee-based Software License Agreement which is granted to "Business Green" Club GreenSock members (see http://www.greensock.com/club/ for details).

C. You may make modifications to the source code exclusively for your own use in order to perform bug fixes or other minor edits required to operate the PROGRAM as originally intended.

IV. TITLE AND OWNERSHIP
A. The PROGRAM is licensed, not sold, and is protected by copyright laws and international treaty provisions. You acknowledge that no title to the intellectual property in the PROGRAM is transferred to you. You further acknowledge that title and full ownership rights to the PROGRAM, including all intellectual property rights therein, will remain the exclusive property of GREENSOCK and you will not acquire any rights to the PROGRAM except as expressly set forth in this Agreement. You agree that any copies of the PROGRAM you make will contain the same proprietary notices which appear on and in the PROGRAM. You agree that GREENSOCK may identify you as a licensee unless you make a written request otherwise. GREENSOCK hereby grants to you the right to disclose that your product, game, software application, component, or other Developed Work makes use of GREENSOCK code (for example, "Powered by TweenLite").

V. DISCLAIMER OF WARRANTY AND LIMITATION OF LIABILITY
A. THE PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. GREENSOCK DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED IN THE PROGRAM WILL MEET YOUR REQUIREMENTS OR THAT OPERATION WILL BE UNINTERRUPTED OR ERROR FREE. GREENSOCK shall not be liable for special, indirect, incidental, or consequential damages with respect to any claim on account of or arising from this Agreement or use of the PROGRAM, even if GREENSOCK has been or is hereafter advised of the possibility of such damages. Because some states do not allow certain exclusions or limitations on implied warranties or of liability for consequential or incidental damages, the above exclusions may not apply to you. In no event, however, will GREENSOCK be liable to you, under any theory of recovery, in an amount in excess of $250. Notwithstanding anything else in this agreement, you agree to indemnify GREENSOCK, its assignees, and licensees, and hold each of them harmless from and against any and all claims, losses, damages, and expenses, including legal fees arising out of or resulting from any negligent act or omission by you.

B. GREENSOCK may, at its sole discretion, provide support services related to the PROGRAM, but has no obligation to do so.

VI. TERMINATION
If you at any time fail to abide by the terms of this Agreement, GREENSOCK shall have the right to immediately terminate the license granted herein and pursue any other legal or equitable remedies available.

VII. MISCELLANEOUS
A. This Agreement shall be construed in accordance with the laws of the State of Illinois. In the event of any dispute between you and GREENSOCK with respect to this Agreement, we both agree that if we cannot resolve the dispute in good faith discussion, either of us may submit the dispute for resolution to arbitration with the American Arbitration Association before a single arbitrator using the AAA Rules for Commercial Arbitration. The arbitrator's decision is final and can be enforced in any court with jurisdiction over such matters.

B. This agreement represents the complete and exclusive statement of the agreement between GREENSOCK and you and supersedes all prior agreements, proposals, representations and other communications, verbal or written, between them with respect to use of the program. This agreement may be modified only with the mutual written approval of authorized representatives of the parties.

C. The terms and conditions of this Agreement shall prevail notwithstanding any different, conflicting, or additional terms or conditions which may appear in any purchase order or other document submitted by you. You agree that such additional or inconsistent terms are deemed rejected by GREENSOCK.

D. GREENSOCK and you agree that any xerographically or electronically reproduced copy of this Agreement shall have the same legal force and effect as any copy bearing original signatures of the parties.

Copyright 2006-2013, GreenSock, Inc. Updated 2012-08-28

I'd like to learn how to get bonus plugins, update notifications, SVN access, and more.
To continue, you must agree to the following license: