Load Image from URL in Javascript/HTML5 - how to?

Monkey Targets Forums/HTML5/Load Image from URL in Javascript/HTML5 - how to?

matty(Posted 2013) [#1]
Hi,

I've played around with mojo a little, and tried writing my own native function but am coming unstuck...and it is a little hard to know what I'm doing wrong.

Is it possible to remove the reference to "data/" in mojo or write our own function for loading an image that will allow us to load an image from any URL?

I'm thinking that it would be good to be able to write a game that does not need to load its assets all at the one time but instead can load them from a URL as an when it is needed...which would also allow for expansion more easily...simply add images/sounds etc to a web location and then import them as and when needed.

Maybe monkey cannot do this though?

I don't care about being able to do this in other targets...just html5.


FelipeA(Posted 2013) [#2]
It's weird to see that html5 and other targets don't load images from url. Android and iOS can do that with LoadImage(url), but others like html5, flash or glfw you can't, even though from my experience with html5 and flash you can.

On html5 it should be as easy as:
var img = new Image();
img.src = url;
img.onload = function(){
// draw and stuff..
};



David Casual Box(Posted 2013) [#3]
According to the official documentation, LoadImage is supposed to be able to load from an URL with html5. I filled up a bug for that.

Without this kind of feature, it's not possible to show any facebook user picture.

And because we cannot add pictures in the data directory after the compilation, there is no workaround :((((


David Casual Box(Posted 2013) [#4]
It works!

Look at the solution form Mark itself:
http://monkeycoder.co.nz/Community/posts.php?topic=5271