Although loading an image in openFL is straight forward, I got no luck loading an image…
var bitmapData:BitmapData = Assets.getBitmapData("assets/circuits/1/thumb.png");
var bitmap:Bitmap = new Bitmap(bitmapData);
However, I got this error:
Assets.hx:149: [openfl.Assets] There is no BitmapData asset with an ID of "assets/circuits/1/thumb.png"
thumb.png is there, but I still get the error.
I am trying to target windows.
At my build.xml, I am referring to assets as:
<assets path="Assets" rename="assets"/>
Could it be because I am using:
Did you check if the file is indeed in a
assets/circuits/1/ folder next to the executable?
Openfl-legacy shouldn’t be a problem here.
Does this problem happens with other images, all, or just this one?
Yes, assets/circuits/1/ is next to executable
The problem happens with other images also…
Ok, I found that image will load fine only if I have it stored in assets/circuits/1/ in the project source folder before building the project.
But, if I removed it from project source folder and copied it next to the executable, and try to build or run executable it will not load … ! I don’t know why…
You need to store your assets in the project folder,
they will be copied next to the executable and listed,
you can’t load an asset that wasn’t there during the build since it’s not in the list.
In my project, thumbs are generated and stored in the assets folder, but they can’t be loaded, although images that where there in the project source folder will be loaded fine…
So, I need to store& load new thumbs in production … how?
Then you can use the
fromFile method of the BitmapData class: http://docs.openfl.org/openfl/display/BitmapData.html#fromFile
fromFile is great, but its not supported in legacy mode… how would I load images then?
fromFile only works on native targets, because those targets have access to the file system.
Assets.getBitmapData uses a library cache that embeds resources in such a way - regardless of platform - that it requires mapping to the given directories at compile-time. If you look into
ApplicationMain.hx in the
haxe output folder, you will see that it will map the resources accordingly.
If the resources are not mapped, the executable won’t find the resource, even if it technically exists.
Thanks tienery for the info, do you mean that Assets.getBitmapData will result in using the same bitmapData for multiple bitmaps? what about loading images using URLRequest? is there a caching for such case in openFL?
I have finally loaded the images by using full path in local storage directory using URLRequest
Yes, if the location is the same as before. When you request a new resource via that very function, it will grab it from its mapped location, relative to the executable folder. If it’s bytecode, like Flash, then it acquires the symbol within its SWF resource.
URLRequest takes a HTTP URL and downloads the content for use in the project. It doesn’t do mapping in this sense, because it assumes it is an external resource. This is different in the case of Flash, however, since Flash has it’s own class which OpenFL binds to. See here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html
In terms of Flash, using a local storage location can cause security sandbox exceptions. Not sure if this is the same on native.
Thanks for detailed answer, infact, I am targeting Android, which should be fine to read/write from local storage I hope…