Easy loader for many things, including managing multiple downloads.
More documentation coming.
protected var _complete:Function
protected var _forEach:Boolean
protected var _remaining:int = 0
protected var _result:Object
protected var _targetsToKeys:Dictionary
public function MultiLoader(sources:Object, completeCallback:Function, generatorFn:Function = null, forEach:Boolean = false, isCompleteCheckFn:String = null, errorTypes:Array = null, completeType:String = null)
Coordinate loading some asynchronous objects.
Parameters
| sources:Object — An Array, Dictionary, or Object of sources, or just a single source.
|
|
| completeCallback:Function — the function to call when complete.
|
|
| generatorFn:Function (default = null ) — a function to call to generate the IEventDispatchers, or
null if the source values are already ready to go.
|
|
| forEach:Boolean (default = false ) — whether to call the completeCallback for each source, or all-at-once at
the end. If forEach is used, keys will never be returned.
|
|
| isCompleteCheckFn:String (default = null ) — a function to attempt to call on the dispatcher to see if
it's already complete after generation.
|
|
| errorTypes:Array (default = null ) — an Array of event types that will be dispatched by the loader.
If unspecifed, all the normal error event types are used.
|
|
| completeType:String (default = null ) — the event complete type. If unspecifed |
protected function checkReport(key:*):void
Parameters
public static function getContents(sources:Object, completeCallback:Function, forEach:Boolean = false, appDom:ApplicationDomain = null):void
Load one or more sources and return DisplayObjects.
Parameters
| sources:Object — an Array, Dictionary, or Object containing sources as values, or a single
source value. The sources may be Strings (representing urls), URLRequests, ByteArrays,
or a Class that can be instantiated to become a URLRequest or ByteArray. Note that
the format of your sources Object dictates the format of the return Object.
|
|
| completeCallback:Function — the function to call when complete. The signature should be:
function (value :Object) :void . Note that the structure of the return Object
is dictated by the sources parameter. If you pass in an Array, you get your results
in an Array. If you use a Dictionary or Object, the results will be returned as the same,
with the same keys used in sources now pointing to the results. If your sources parameter
was just a single source (like a String) then the result will just be a single result,
like a DisplayObject. Each result will be a DisplayObject or an Error
describing the problem.
|
|
| forEach:Boolean (default = false ) — if true, each value or error will be returned as soon as possible. The values
or errors will be returned directly to the completeCallback. Any keys are lost, so you
probably only want to use this with an Array sources.
|
|
| appDom:ApplicationDomain (default = null ) — the ApplicationDomain in which to load the contents, or null to specify
that it should load in a child of the current ApplicationDomain.
|
Example
Load one embed, add it as a child.
MultiLoader.getContents(EMBED_CONSTANT, addChild);
Load 3 embeds, add them as children.
MultiLoader.getContents([EMBED1, EMBED2, EMBED3], addChild, true);
Load multiple URLs, have the contents returned to the result function one at
a time.
function handleComplete (result :Object) :void {
// process a result here. Result may be a DisplayObject or an Error.
};
var obj :Object = {
key1: "http://somehost.com/someImage.gif",
key2: "http://somehost.com/someOtherImage.gif"
};
MultiLoader.getContents(obj, handleComplete, true);
Load 3 embeds, wait to handle them until they're all loaded.
function handleComplete (results :Array) :void {
// process results here
};
MultiLoader.getContents([EMBED1, EMBED2, EMBED3], handleComplete);
public static function getLoaders(sources:Object, completeCallback:Function, forEach:Boolean = false, appDom:ApplicationDomain = null):void
Exactly like getContents() only it returns the Loader objects rather than their contents.
Parameters
| sources:Object |
|
| completeCallback:Function |
|
| forEach:Boolean (default = false )
|
|
| appDom:ApplicationDomain (default = null )
|
See also
getContents()
Example
Advanced usage: Loading classes.
// A holder for new classes, created as a child of the system domain.
var appDom :ApplicationDomain = new ApplicationDomain(null);
function handleComplete (results :Object) :void {
// now we can retrieve classes
var clazz :Class = appDom.getDefinition("com.package.SomeClass") as Class;
}
// load all the classes contained in the specified sources
MultiLoader.getLoaders([EMBED, "http://site.com/pack.swf"], handleComplete, false, appDom);
[Embed(source="resource.swf", mimeType="application/octet-stream")]
private static const EMBED :Class;
protected function handleComplete(event:Event):void
Parameters
protected function handleError(event:ErrorEvent):void
Parameters
public static function loadClasses(sources:Object, appDom:ApplicationDomain, completeCallback:Function):void
Loads classes into the specified ApplicationDomain.
The complete callback receives either the same ApplicationDomain or no arguments.
Parameters
| sources:Object |
|
| appDom:ApplicationDomain |
|
| completeCallback:Function |
protected static function processProperty(retval:Object, testClass:Class, prop:String):Object
Utility method used in this class.
Parameters
| retval:Object |
|
| testClass:Class |
|
| prop:String |
Returns
protected static const _activeMultiLoaders:Dictionary
Copyright © 2007-2009 Three Rings Design, Inc.