Browse Source

Added a throw in BinaryLoader for unsupported platforms (#807)

Sébastien Bénard 5 years ago
parent
commit
d4879c4dc4
1 changed files with 12 additions and 6 deletions
  1. 12 6
      hxd/net/BinaryLoader.hx

+ 12 - 6
hxd/net/BinaryLoader.hx

@@ -23,29 +23,30 @@ class BinaryLoader {
 
 	public function load() {
 		#if flash
+
 		loader = new flash.net.URLLoader();
 		loader.dataFormat = flash.net.URLLoaderDataFormat.BINARY;
 		loader.addEventListener(flash.events.IOErrorEvent.IO_ERROR, function(e:flash.events.IOErrorEvent) onError(e.text));
 		loader.addEventListener(flash.events.Event.COMPLETE, function(_) onLoaded(haxe.io.Bytes.ofData(loader.data)));
 		loader.addEventListener(flash.events.ProgressEvent.PROGRESS, function(e:flash.events.ProgressEvent) onProgress(Std.int(e.bytesLoaded), Std.int(e.bytesTotal)));
 		loader.load(new flash.net.URLRequest(url));
-		#end
-			
-		#if js
+
+		#elseif js
+
 		var xhr = new js.html.XMLHttpRequest();
 		xhr.open('GET', url, true);
 		xhr.responseType = js.html.XMLHttpRequestResponseType.ARRAYBUFFER;
 		xhr.onerror = function(e) onError(xhr.statusText);
-		
+
 		xhr.onload = function(e) {
-			
+
 			if (xhr.status != 200) {
 				onError(xhr.statusText);
 				return;
 			}
 			onLoaded(haxe.io.Bytes.ofData(xhr.response));
 		}
-		
+
 		xhr.onprogress = function(e) {
 			#if (haxe_ver >= 4)
 			onProgress(Std.int(js.Syntax.code("{0}.loaded || {0}.position", e)), Std.int(js.Syntax.code("{0}.total || {0}.totalSize", e)));
@@ -54,6 +55,11 @@ class BinaryLoader {
 			#end
 		}
 		xhr.send();
+
+		#else
+
+		throw "Not available on this platform";
+
 		#end
 	}