From fa5ed0a6301dd9ad49c3063ac616e63a1510df41 Mon Sep 17 00:00:00 2001 From: Andy Woods Date: Fri, 8 Jul 2016 10:14:13 +0100 Subject: [PATCH] multiple attempts to load a file, in BaseLoader I also added a small random time delay. --- src/assets/manager/loaders/BaseLoader.hx | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/assets/manager/loaders/BaseLoader.hx b/src/assets/manager/loaders/BaseLoader.hx index b276211..235383e 100644 --- a/src/assets/manager/loaders/BaseLoader.hx +++ b/src/assets/manager/loaders/BaseLoader.hx @@ -28,6 +28,7 @@ class BaseLoader extends EventDispatcher { public var data(default, null):Dynamic; public var status(default, null):LoaderStatus; public var error(default, null):String; + public var attempts:Int = 5; function new(id:String, type:FileType) { super(); @@ -48,10 +49,20 @@ class BaseLoader extends EventDispatcher { } function onLoadFail(e:ErrorEvent) { - data = null; - error = e.toString(); - status = LoaderStatus.ERROR; - dispatchEvent(new Event(Event.COMPLETE)); + if (attempts >= 0) { + trace(attempts); + Timer.delay(function() { + start(); + }, Std.int(Math.random() * 100)); + attempts--; + } + else { + data = null; + error = e.toString(); + status = LoaderStatus.ERROR; + trace('xpt loading error:', e.toString()); + dispatchEvent(new Event(Event.COMPLETE)); + } } function processData() { @@ -73,4 +84,4 @@ class BaseLoader extends EventDispatcher { loader.load(new URLRequest(id)); } -} \ No newline at end of file +}