Two fixes:
- Added a mechanism for testing if something is already loaded after generation. DataPacks load immediately if passed a ByteArray. Loaders will always wait a frame, so I was going to change DataPack to follow that behavior, but it's nice that it just works right after construction. - If a singleton source was passed in and resulted in an error (or, now, it can already be loaded as well) then it would incorrectly return as the result the internal wrapper object for the single result. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4969 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -154,13 +154,16 @@ public class MultiLoader
|
||||
* @param completeCallack the function to call when complete.
|
||||
* @param forEach whether to call the completeCallback for each source, or all-at-once at
|
||||
* the end. If forEach is used, keys will never be returned.
|
||||
* @param isCompleteCheckFn a function to attempt to call on the dispatcher to see if
|
||||
* it's already complete after generation.
|
||||
* @param errorTypes an Array of event types that will be dispatched by the loader.
|
||||
* If unspecifed, all the normal error event types are used.
|
||||
* @param completeType, the event complete type. If unspecifed @default Event.COMPLETE.
|
||||
*/
|
||||
public function MultiLoader (
|
||||
sources :Object, generatorFn :Function, completeCallback :Function,
|
||||
forEach :Boolean = false, errorTypes :Array = null, completeType :String = null)
|
||||
forEach :Boolean = false, isCompleteCheckFn :String = null,
|
||||
errorTypes :Array = null, completeType :String = null)
|
||||
{
|
||||
if (errorTypes == null) {
|
||||
errorTypes = [ ErrorEvent.ERROR, AsyncErrorEvent.ASYNC_ERROR,
|
||||
@@ -173,6 +176,7 @@ public class MultiLoader
|
||||
_complete = completeCallback;
|
||||
_forEach = forEach;
|
||||
|
||||
var endCheckKey :* = null;
|
||||
if (sources is Array) {
|
||||
_result = new Array();
|
||||
|
||||
@@ -184,6 +188,7 @@ public class MultiLoader
|
||||
if (!Util.isPlainObject(sources)) {
|
||||
// stash the singleton source
|
||||
sources = { singleton_key: sources };
|
||||
endCheckKey = "singleton_key";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,12 +203,14 @@ public class MultiLoader
|
||||
}
|
||||
_result[key] = val;
|
||||
if (val is IEventDispatcher) {
|
||||
var ed :IEventDispatcher = IEventDispatcher(val);
|
||||
_remaining++;
|
||||
_targetsToKeys[ed] = key;
|
||||
ed.addEventListener(completeType, handleComplete);
|
||||
for each (var type :String in errorTypes) {
|
||||
ed.addEventListener(type, handleError);
|
||||
if (isCompleteCheckFn == null || !val[isCompleteCheckFn]()) {
|
||||
var ed :IEventDispatcher = IEventDispatcher(val);
|
||||
_remaining++;
|
||||
_targetsToKeys[ed] = key;
|
||||
ed.addEventListener(completeType, handleComplete);
|
||||
for each (var type :String in errorTypes) {
|
||||
ed.addEventListener(type, handleError);
|
||||
}
|
||||
}
|
||||
} else if (_forEach) {
|
||||
checkReport(key);
|
||||
@@ -211,7 +218,7 @@ public class MultiLoader
|
||||
}
|
||||
|
||||
if (!_forEach) {
|
||||
checkReport(null);
|
||||
checkReport(endCheckKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user