Issue with embedded BitmapData

I want to continue to think about the behavior of embedded assets (such as using @:bitmap), but in the meantime I have made a small patch to Lime that allows another workaround

project.xml

<assets path="Assets" rename="assets" exclude="preloader" />
<assets path="Assets/preloader" rename="" embed="true" library="preloader" />

Preloader.hx

Assets.loadBitmapData ("preloader:graphic.png").onComplete (function (bitmapData) {
    // handle bitmapData
});

Lime 4 included the new ability to split up your assets into separate asset libraries. The reason why this comes in handy (in this case) is that we can make all the assets we want for the preloader embedded, and available without preloading.

The “default” library (or any other library) can preload as normal, but within your preloader you should be able to access your assets.

We prefetch embedded assets on the HTML5 target during the preload process, but if you are in the preloader, you’ll need the async loadBitmapData method for them to work properly. getBitmapData works on native here.

Open to feedback, but hopefully this helps lend more flexibility to preloading.

EDIT:

As an alternative, realized (with the above “preloader” asset library) the following code can also work:

Assets.loadLibrary ("preloader").onComplete (function (_) {
    var bitmapData = Assets.getBitmapData ("preloader:graphic.png");
    // handle bitmapData
});

Perhaps loadBitmapData is still nicer, though – depends on whether you want to wait once for all embedded assets, or wait separately :slight_smile:

2 Likes