OpenFL has it’s own asset system, which should be simple to use. It includes automatic preloading for you on HTML5, and we can embed assets in your SWF, we can also asynchronously load assets that you provide at compile-time, not preloading them but requesting them later.
The simplest case is visible in most of the OpenFL samples, such as “DisplayingABitmap”.
The project.xml has the following:
<asset path="Assets" rename="assets" />
…then in Haxe
var bitmapData = Assets.getBitmapData ("assets/openfl.png");
You can use openfl.utils.Assets
for images, sound, fonts, text, bytes and even SWF-based MovieClip assets. By default, all your assets are preloaded on HTML5 (and no preloading is necessary on native), so you can get
your assets immediately when you need them. There are also load
methods (like Assets.loadBitmapData
) which you can use for assets that were not preloaded
<asset path="Assets" rename="assets" embed="false" />
Assets.loadBitmapData ("assets/openfl.png").onComplete (function (bitmapData) {
...
});
We provide a default Preloader
class (with a progress bar, colored based on your application background color) but you can provide a different Preloader
class of your own to customize how this looks. We design this on Flash so that the preloader is embedded in the same SWF, which is convenient. If you want a custom preloader, you can try out the “CustomPreloader” sample
openfl create CustomPreloader
cd CustomPreloader
openfl test html5 -Dsimulate-preloader
(the simulate-preloader
define triggers a fixed amount of time for preloading, which is useful to test how your preloader will look, you can also do -Dsimulate-preloader=5000
or other values to change the amount of time it will take)
Currently, we support HTML5 video on HTML5, and Flash Video on Flash, but there is no official support on native platforms yet without using another library