[CLASS] OpenFL custom Preloader Example

I’ve written a very simple example about custom preloader, easy to understand and so to be customized for others needs.

It offers a bar (like the original one), a glowing effect (easy to remove) and a fluid layout to fit nicely any resolution/resize.

I want to share this with you because it took me some time to understand how to do it since I haven’t found straight resources about this.

All the documentation, demo and the very project is on this github repo

I’m pretty new to HAXE/OpenFL so if you want to improve it or fix any mistake I’ve made, please do it.

See ya


Thanks yupswing !
I may rebuild my game without HaxePunk (to reach better performances), and this is definitly going to be of great help.
Keep going on !

happy that is useful to you

Does the preloader allow to load xml files, connect to web server in different steps before start loading the main app resources?

I have to load configuration xmls, call services based on the configuration, load other resources based on service reply etc, and after all this load the main application resources, that can change depending on the configuration and the services reply.

this preloader allows to show some feedback while the app is loading its own content (assets). it works in flash and web targets.
you are talking about another stage you have to build.

nothing stops you from integrate the two stages in one, but the nmepreloader will be always first because as shown in the code you don’t control the preload process, you just witness it and you can listen to the updates to show the user a progress bar

Does the progress bar show the loading process of all the resource assets contained in the folders specified in the project.xml? If so, I think I should do all the steps I listed AFTER that, right?

I see problem, regarding the placement of “logo” on html5 target.
First of all, splash.width and height is not accessible for some reasons. Also, x,y,scaleX, and scaley generate wrong placement. However, all these work fine on Flash.

If the file’s being loaded, it’s asynchronous (but handled internally within bitmapData), so might need to wait for it to load completely before checking the size

Yes, i noticed that. It takes a bit of time. Using an EnterFrame event would probably help in this case.

It looks like for me even EnterFrame cannot help to detect the width & height of embedded bitmaps (html5). When i tracing the size on each frame, i’m getting “Infinity” in values or “NaN”. Is there is any solution to this problem?

I do not know, I developed this custom preloader for Flash (and it works in HTML5 as a preloader is supported by OpenFL on both platforms).

I have no time to work on it right now, so if you want to give it a try and make a pull request on the repository I would be happy to merge it.


can I use this on Android projects?

Android apps don’t need a preloader. By the time you launch the app, the download is complete.

if you use swf to get assets there is a lot of freezes in android and neko target

Maybe this could be useful

In that case, you want a regular loader, not a preloader. Do the work on a separate thread (also available for Neko), periodically dispatching progress messages. When the main thread receives a progress message, update the loading bar.

Actually, depending on what’s causing the lag, you might not have to go to that much trouble. If you disable preload="true" and use Assets.loadLibrary(), it will do the first part of the work asynchronously. If that turns out to be what was causing the freezes, then you’re done!

cant find a real solution, the aplication freezes always

if I wait 70 seconds all works fine, so I create a timer and a bar:

100 % charge bar is on 70 second, but this is like a trick not a real loader