|
@@ -23,29 +23,30 @@ class BinaryLoader {
|
|
|
|
|
|
public function load() {
|
|
public function load() {
|
|
#if flash
|
|
#if flash
|
|
|
|
+
|
|
loader = new flash.net.URLLoader();
|
|
loader = new flash.net.URLLoader();
|
|
loader.dataFormat = flash.net.URLLoaderDataFormat.BINARY;
|
|
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.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.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.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));
|
|
loader.load(new flash.net.URLRequest(url));
|
|
- #end
|
|
|
|
-
|
|
|
|
- #if js
|
|
|
|
|
|
+
|
|
|
|
+ #elseif js
|
|
|
|
+
|
|
var xhr = new js.html.XMLHttpRequest();
|
|
var xhr = new js.html.XMLHttpRequest();
|
|
xhr.open('GET', url, true);
|
|
xhr.open('GET', url, true);
|
|
xhr.responseType = js.html.XMLHttpRequestResponseType.ARRAYBUFFER;
|
|
xhr.responseType = js.html.XMLHttpRequestResponseType.ARRAYBUFFER;
|
|
xhr.onerror = function(e) onError(xhr.statusText);
|
|
xhr.onerror = function(e) onError(xhr.statusText);
|
|
-
|
|
|
|
|
|
+
|
|
xhr.onload = function(e) {
|
|
xhr.onload = function(e) {
|
|
-
|
|
|
|
|
|
+
|
|
if (xhr.status != 200) {
|
|
if (xhr.status != 200) {
|
|
onError(xhr.statusText);
|
|
onError(xhr.statusText);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
onLoaded(haxe.io.Bytes.ofData(xhr.response));
|
|
onLoaded(haxe.io.Bytes.ofData(xhr.response));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
xhr.onprogress = function(e) {
|
|
xhr.onprogress = function(e) {
|
|
#if (haxe_ver >= 4)
|
|
#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)));
|
|
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
|
|
#end
|
|
}
|
|
}
|
|
xhr.send();
|
|
xhr.send();
|
|
|
|
+
|
|
|
|
+ #else
|
|
|
|
+
|
|
|
|
+ throw "Not available on this platform";
|
|
|
|
+
|
|
#end
|
|
#end
|
|
}
|
|
}
|
|
|
|
|