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 completeCallack the function to call when complete.
|
||||||
* @param forEach whether to call the completeCallback for each source, or all-at-once at
|
* @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.
|
* 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.
|
* @param errorTypes an Array of event types that will be dispatched by the loader.
|
||||||
* If unspecifed, all the normal error event types are used.
|
* If unspecifed, all the normal error event types are used.
|
||||||
* @param completeType, the event complete type. If unspecifed @default Event.COMPLETE.
|
* @param completeType, the event complete type. If unspecifed @default Event.COMPLETE.
|
||||||
*/
|
*/
|
||||||
public function MultiLoader (
|
public function MultiLoader (
|
||||||
sources :Object, generatorFn :Function, completeCallback :Function,
|
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) {
|
if (errorTypes == null) {
|
||||||
errorTypes = [ ErrorEvent.ERROR, AsyncErrorEvent.ASYNC_ERROR,
|
errorTypes = [ ErrorEvent.ERROR, AsyncErrorEvent.ASYNC_ERROR,
|
||||||
@@ -173,6 +176,7 @@ public class MultiLoader
|
|||||||
_complete = completeCallback;
|
_complete = completeCallback;
|
||||||
_forEach = forEach;
|
_forEach = forEach;
|
||||||
|
|
||||||
|
var endCheckKey :* = null;
|
||||||
if (sources is Array) {
|
if (sources is Array) {
|
||||||
_result = new Array();
|
_result = new Array();
|
||||||
|
|
||||||
@@ -184,6 +188,7 @@ public class MultiLoader
|
|||||||
if (!Util.isPlainObject(sources)) {
|
if (!Util.isPlainObject(sources)) {
|
||||||
// stash the singleton source
|
// stash the singleton source
|
||||||
sources = { singleton_key: sources };
|
sources = { singleton_key: sources };
|
||||||
|
endCheckKey = "singleton_key";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,12 +203,14 @@ public class MultiLoader
|
|||||||
}
|
}
|
||||||
_result[key] = val;
|
_result[key] = val;
|
||||||
if (val is IEventDispatcher) {
|
if (val is IEventDispatcher) {
|
||||||
var ed :IEventDispatcher = IEventDispatcher(val);
|
if (isCompleteCheckFn == null || !val[isCompleteCheckFn]()) {
|
||||||
_remaining++;
|
var ed :IEventDispatcher = IEventDispatcher(val);
|
||||||
_targetsToKeys[ed] = key;
|
_remaining++;
|
||||||
ed.addEventListener(completeType, handleComplete);
|
_targetsToKeys[ed] = key;
|
||||||
for each (var type :String in errorTypes) {
|
ed.addEventListener(completeType, handleComplete);
|
||||||
ed.addEventListener(type, handleError);
|
for each (var type :String in errorTypes) {
|
||||||
|
ed.addEventListener(type, handleError);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (_forEach) {
|
} else if (_forEach) {
|
||||||
checkReport(key);
|
checkReport(key);
|
||||||
@@ -211,7 +218,7 @@ public class MultiLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!_forEach) {
|
if (!_forEach) {
|
||||||
checkReport(null);
|
checkReport(endCheckKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user