diff --git a/lime/graphics/Image.hx b/lime/graphics/Image.hx index 300c36de9..90a277b01 100644 --- a/lime/graphics/Image.hx +++ b/lime/graphics/Image.hx @@ -21,6 +21,7 @@ import lime.math.color.RGBA; import lime.math.ColorMatrix; import lime.math.Rectangle; import lime.math.Vector2; +import lime.net.HTTPRequest; import lime.system.CFFI; import lime.utils.ArrayBuffer; import lime.utils.UInt8Array; @@ -477,7 +478,7 @@ class Image { } - public static function fromBase64 (base64:String, type:String, onload:Image->Void):Image { + public static function fromBase64 (base64:String, type:String #if (lime < "4.0.0"), onload:Image->Void #end):Image { if (base64 == null) return null; var image = new Image (); @@ -505,7 +506,7 @@ class Image { } - public static function fromBytes (bytes:Bytes, onload:Image->Void = null):Image { + public static function fromBytes (bytes:Bytes #if (lime < "4.0.0"), onload:Image->Void = null #end):Image { if (bytes == null) return null; var image = new Image (); @@ -531,7 +532,7 @@ class Image { } - public static function fromFile (path:String, onload:Image -> Void = null, onerror:Void -> Void = null):Image { + public static function fromFile (path:String #if (lime < "4.0.0"), onload:Image -> Void = null, onerror:Void -> Void = null #end):Image { if (path == null) return null; var image = new Image (); @@ -912,7 +913,20 @@ class Image { #else - return new Future (function () return fromFile (path), true); + var request = new HTTPRequest (); + return request.load (path).then (function (image) { + + if (image != null) { + + return Future.withValue (image); + + } else { + + return cast Future.withError (""); + + } + + }); #end diff --git a/lime/media/AudioBuffer.hx b/lime/media/AudioBuffer.hx index f5ce786ce..2dd7797eb 100644 --- a/lime/media/AudioBuffer.hx +++ b/lime/media/AudioBuffer.hx @@ -235,6 +235,7 @@ class AudioBuffer { } + #if (lime < "4.0.0") public static function fromURL (url:String, handler:AudioBuffer->Void):Void { #if (js && html5 && howlerjs) @@ -285,6 +286,7 @@ class AudioBuffer { #end } + #end #if lime_vorbis @@ -380,10 +382,18 @@ class AudioBuffer { // TODO: Streaming - var request = new HTTPRequest (); - return request.load (path).then (function (bytes) { + var request = new HTTPRequest (); + return request.load (path).then (function (buffer) { - return Future.withValue (AudioBuffer.fromBytes (bytes)); + if (buffer != null) { + + return Future.withValue (buffer); + + } else { + + return cast Future.withError (""); + + } }); diff --git a/lime/text/Font.hx b/lime/text/Font.hx index 64a021cb6..622428ced 100644 --- a/lime/text/Font.hx +++ b/lime/text/Font.hx @@ -8,6 +8,7 @@ import lime.app.Promise; import lime.graphics.Image; import lime.graphics.ImageBuffer; import lime.math.Vector2; +import lime.net.HTTPRequest; import lime.system.System; import lime.utils.UInt8Array; @@ -129,7 +130,20 @@ class Font { public static function loadFromFile (path:String):Future { - return Future.withValue (fromFile (path)); + var request = new HTTPRequest (); + return request.load (path).then (function (font) { + + if (font != null) { + + return Future.withValue (font); + + } else { + + return cast Future.withError (""); + + } + + }); }