Load image from external address

I’m trying to load an image from an external URL other than the project address (html5).

In HTML5 it does not return an error. It just doesn’t run the project. In NEKO, this message appears:

Uncaught exception - [lime.utils.Assets] ERROR: There is no asset library named “https”
I’ve tried to change the asset tag, and put the https:… address instead, but it doesn’t accept.

I have it today.

Do I need any security permissions?

Thank you!

Can your provide a sample of your code?

It looks like you’re attempting to load a remote image using Assets.getBitmapData or Assets.loadBitmapData. That only works for assets included with your application.

Use the static function BitmapData.loadFromFile(…) like so:

BitmapData.loadFromFile("https://www.someurl.com/my_image.png").onComplete( someCallback );

function someCallback(bmpd:BitmapData):Void { 
    ///add your code to display the bitmap here
}
1 Like

The openfl.display.Loader class may also be used for loading image files.

var url = "https://www.example.com/image.jpg";
var urlRequest = new URLRequest(url);
var loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
loader.load(urlRequest);
addChild(loader);
 
function loader_complete(event:Event):Void {
    trace("complete");
}
1 Like

Exactly friend. As I am new to the language, I made this mistake.
Thanks so much for everyone’s help! This community really works :wink: