Hi,
Iād like to know if I can preload remote resources with the asynchronous load### functions and use them later synchronously by getting them with get### functions, without saving the contents I receive when loading is complete.
I other words, is it possible to āconvertā at runtime non-embedded resources to embedded-resources?
I tried (i.e. Assets.loadSound(ābang.mp3ā, true), loading completes and later I use getSound(ābang.mp3ā)) but it tells me the resource must be loaded asynchronously, as if it hasnāt been downloaded yet, even if the ācacheā parameter of the load function is set to true. Am I using the wrong method to get the downloaded resources? Do I have to save all resources apart during the preload phase? It would be very uncomfortable.
It should work this way, so letās hunt down cases where this might not be true. This use-case hasnāt been tested much, but Iād like to see it happen.
Perhaps this is an issue between lime.Assets cache and openfl.Assets cache, it is cached in lime.Assets, but not openfl.Assets, so it doesnāt return, so we just need to get that synced
Hmm, Iām not sure. We probably need to check the lime.Assets cache, and if it is cached there, use that as the source for loading. Otherwise, we also need to make sure that clearing the OpenFL cache can clear the Lime cache (I thought it did, but its worth checking again)
I think I have found where the problem is: it looks like I can use Assets.loadBitmapData and get the image data later with getBitmapData as if it was embedded, because cache works correctly for images (well, it is a parameter of the function ), but NOT for XML files: loadText has no parameter āuseCacheā, so I canāt preload it to use later.
I think the fix is pretty easy, but I should have a look at how cache works.
EDIT: Ah! In Assets.hx - AssetCache I see
bitmapData = new Map<String, BitmapData> ();
font = new Map<String, Font> ();
sound = new Map<String, Sound> ();
ā¦this means that XMLs cannot be cached?! Neither lime.Assets caches XMLs!
What about adding
text = new Map<String, String> ();
?
EDIT2: looking at lime.Assets: seems like xml files MUST be cached.
EDIT3: openfl.Assets modified to allow text caching! Now I have a local cache in singleton openfl.Assets.hx for texts too! Ignoring lime.Assets ācacheā.
BitmapData, Font and Sound resources are class instances. They can be shared and re-used multiple times. There is a local cache in Assets to allow repeated requests, without creating duplicate instances of the same data.
For ByteArray and String resources, they are more ārawā and often are manipulated after use. In the case of String, a cache would probably make little sense? (these types of files are also less likely to be used repeatedly)
On HTML5, when embedded, these are preloaded, and pulled in internally. I suppose in the loadText or loadBytes sense, it could be nice to have them cached, but can you just flag your XML file as embedded? Is it defined at runtime?
Xmls are set as non-embedded
If I try to load an xml with loadText and then get it with getText it tells me I can only get it asynchronously -> by loadText.
Maybe a bug in comunication between openfl.Assets and lime.Assets: openfl.Assets.getText calls lime.Assets.getText, but lime Assets responds the file is not cached, even if I loaded it.
I donāt need to reuse the text files, I just need to load only files version I need and use them later: I have 2 versions, mobile or desktop.
I am using subclasses and modified classes while keeping the original ones, and this works as expected. Well Iād like this to be integrated in the official openfl release, but for now it does what I need.