Loading asset error

Hi there, I am using latest versions of Haxe / OpenFL and Lime and I am facing one issue targeting HTML5.

If I use:

<assets path="assets/images" rename="images" embed="true" />

I have this error on start if there is images in the assets/images path:
message: "[lime.utils.Preloader] ERROR: Error loading asset “images/glasses.png”

Then if I use:

<assets path="assets/images" rename="images" embed="false" />

Assets.loadBitmapData("images/glasses.png").onComplete(function (bitmapData) 
			trace (bitmapData);
			var bitmap = new Bitmap (bitmapData);
			trace (bitmap.width);
			addChild (bitmap);

“onComplete” is never fired…while trace(Assets.exists(“images/glasses.png”)); is true…

Any idea?

Maybe you can open the browser debug page from F12 to see some useful error messages.

When embed=“false” there is no error.

When embed=“true”:

message: "[lime.utils.Preloader] ERROR: Error loading asset \"images/glasses.png\""

If I am testing with ctrl + ENTER from HaxeDevelop everything is working…
Putting HTML online works fine too…

Maybe you are not using lime test html5; It needs to run under the server

I don’t think so.
Command line is:

"$(CompilerPath)/haxelib" run lime build "$(OutputFile)" $(TargetBuild) -$(BuildConfig) -Dfdb

Web browsers act a little differently when running local .html files vs pages from a web server, and it often results in errors when trying to load assets at runtime. With that in mind, you should always launch any type of HTML/JS project (not just OpenFL) from a local web server instead of opening the .html file from the file system. This will ensure that you’ll see the same behavior locally as you do when deploying to production.

Using lime test html5 (or openfl test html5) is the easiest way to do that for OpenFL projects. However, you can certainly use any local web server that you prefer.

Thanks for the explanation sir! :slight_smile:

1 Like