Assets can't find my files

I’m working through the basic tutorials on and I can’t seem to get it to display the image. I’m using FlashDevelop and I’ve got a .png in my assets folder and I’m sure the filename is correct but it says “Assets.hx:303: [Assets] There is no Image asset with an ID of “assets/img/openfl.png”” when I run the debugger.

The code is like this:

var bitmapData = Assets.getBitmapData ("assets/img/openfl.png");
    var bitmap = new Bitmap (bitmapData);
    addChild (bitmap);

It’s very simple code so I don’t see what’s going wrong. Please help!

What does your project.xml look like? It is possible that there is a miss match in the asset path, or that the folder is renamed in the tag.

You were right. There was a bit in the project.xml like this:

<assets path="assets/img" rename="img" />

When I changed my file location to /img/openfl.png without the assets, it worked. However, I only put it in that img folder because I saw it in the project.xml.

When I originally wrote the program I put the image in the root assets folder, and I had the same problem.

Here’s my full project.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- metadata, make sure 'package' is at least 3 segments (ie. com.mycompany.myproject) -->
<meta title="Deviant Dungeon" package="DeviantDungeon" version="1.0.0" company="Arthur Payne" />

<!-- output -->
<app main="Main" file="DeviantDungeon" path="bin" />

<window background="#000000" fps="60" />
<window width="800" height="480" unless="mobile" />
<window orientation="landscape" vsync="false" antialiasing="0" if="cpp" />

<!-- classpath, haxe libs -->
<source path="src" />
<haxelib name="openfl" />
<haxelib name="actuate" />

<!-- assets -->
<icon path="assets/openfl.svg" />
<assets path="assets/img" rename="img" />

<!-- optimize output
<haxeflag name="-dce full" /> -->

Do you have any idea why putting my image in the root assets folder would render it unfindable?

The ‘rename’ attribute decides which path to use when you want to access it.

<assets path="assets/img" rename="something-custom" />

This means that your image should be at assets/img(opengl.png on your file system, but when you want to access them from code you need to write:

 var bitmapData = Assets.getBitmapData ("something-custom/openfl.png");

This way you can set up short cuts to long and complicated asset paths. Works especially well if assets are located in other projects (for whatever reason).

But what if the file isn’t in the renamed folder? When I put it in the root assets folder I have the same error as if I put it in a renamed folder and didn’t use the proper name.

In both cases you ask for something which isn’t there. If you use the ‘rename’ attribute you have to use the renamed path.

I see! Thank you for your help.

1 Like

Just one note, not /img/openfl.png but img/openfl.png… As first slash involves error. And they adding that rename by default, in newly created OpenFL project on HaxeDevelop for Windows. As i saw most of OpenFL tutorials are for *nix systems, where probably far not everything fits for Windows.

1 Like

Assuming xml has rightly specified the Assets tag and target folder

These two still won’t work and generate the confusing error description:

There is no Image asset with an ID of …

var bitmapData = Assets.getBitmapData ("/assets/a.jpg"); // << Won't work because of first slash used for the path

var bitmapData = Assets.getBitmapData ("./assets/a.jpg"); // << Won't work because of first dot and slash used in the path

This will work:

var bitmapData = Assets.getBitmapData ("assets/a.jpg"); // << Works!