Use Assets mechanism during runtime?

Is there a way to use the Assets mechanism during runtime? I know it’s meant to embedded resourced during compile time, but I wondered if there is a way to use it during application startup so the same binary could load different resources from an asset folder.

Are these files you copied with your project at build time, or are they added later?

You could use Assets.loadBitmapData (and other similar calls) to load files asynchronously that were copied to the output directory, but were known at compile time. Otherwise, accessing files at runtime could be done using the Loader or URLLoader class, using Haxe File APIs, or using things such as BitmapData.fromBytes, etc.

We’re working on standardizing a set of static classes to be available to help make it easier to create instances of different core data types at runtime

If your target is Cpp
you can use sys.FileSystem and sys.io.File
and use File.getContent() to get string data

if you want to load asset like PNG / JPEG / WAV… etc
you need load byte data first by using File.getBytes()
and turn byte data into bitmap data or sound by using “format” library

On HTML5 and native next, the following functions are available:

BitmapData.fromBase64()
BitmapData.fromBytes()
BitmapData.fromCanvas() (HTML5 only)
BitmapData.fromFile()
BitmapData.fromImage() (Lime Image)

On native (#if lime_legacy) these are available:

BitmapData.load()
BitmapData.loadFromBytes()
BitmapData.loadFromHaxeBytes()

I’d like to make improvements to the older v2 native codebase to create consistency, so that as many “from” static methods are available consistently everywhere. There should be similar functions for sound, font, etc.

This allows you to decode images using libpng/libjpeg on native, or using the browser’s own image support, rather than handling it manually in Haxe, which performs much better

Thanks for all the replies.

So I guess Loader would work for all targets?

Is there a best practice/preferred way or is it more like Loader would be best for Flash, sys.io.File better for desktop and mobile?

not sure about mobile, since it packed in Apk
but it should work on desktop

wow, so there’s a method in bitmapData will decode image file for you?

Yep! Give it a try :smile: