How to retain load progress bar for all platforms?

When I use asynchronous Loader.load() I have access to ProgressEvent where I can track bytesLoaded to display a progress bar (or percentage loaded).
Unfortunately, not all platforms support this method of loading. And while it is possible to use loadBytes to create images, I don’t see how I can create Sound objects this way (I saw some “MP3 from bytes” libraries for Haxe, but I will need OGG format for all other platforms).

This means, that either I have to give up the loading bar or exclude sounds from runtime loading.
Yet I hope there are those who know a solution for this dilemma… :slight_smile:

P.S. I couldn’t find documentation for SWF library. If it allows extracting OGG files from loaded swfs, the problem is solved.

In the Flash API, you would use URLLoader for plain data (text or bytes), you would use Loader to load an image, or Sound to load a sound, each one has it’s own completion events (but be aware that you must listen to .contentLoaderInfo on the Loader class)

On OpenFL, we also have some utility methods, such as BitmapData.fromFile, and so on, to shortcut the process and skip the full loading method. On native platforms, things are basically “always loaded” because disk IO goes so fast, though we do have plans to add asynchronous loads in another thread, just to prevent the small amount of burden an asset can cause at times (depending on how the project is designed)

Generally speaking, loading is done on HTML5 and Flash, where you are downloading assets from the web, but elsewhere the assets are packaged already, and do not require a loader

Unless they are downloaded from web.

True. Unlike Flash, though, you should be able to load anything from file or bytes on native

If someone shares a code, where oggs are loaded from bytes, that would be great!

It would. Really, it would.

I think something like this might do it:

var bytes = Assets.getBytes ("mysound.ogg");
var sound = new Sound ();
sound.loadCompressedDataFromByteArray (bytes, bytes.length);
sound.play ();

Of course, OGG is only supported on native, not Flash. You can load the ByteArray from somewhere else (such as ByteArray.fromBytes (File.getBytes ("mysound.ogg")); to load from disk somewhere, but be aware this might not work as you expect on mobile platforms such as Android)

1 Like

So, Loader class allows runtime loading of graphics.
Sound class allows runtime loading of sounds.
Only 1 question remains now: what allows runtime loading of TTFs?

Runtime font handling would depend on the platform.

For Flash, you would need to open a SWF that contained the font embedded, or you could use a system font.

For native, you can reference the path to the TTF font at runtime.

For HTML5, it currently uses HTML5 web fonts, so you would need to load or reference an additional web font to use it

Thanks for all the answers.

Where can i read about it?

Here’s one solution: