I’m working through the basic tutorials on http://www.openfl.org/learn/tutorials/your-first-project/ 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!
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.
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.
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.