Preloader , now that NMEPreloader is depreciated

I’m seeing messages when compiling that NMEPreloader has now been depreciated. Despite still working when i target HTML (although not flash and neko).

The method of creating a replacement preloader by extending NMEPreloader and overriding the functions new() , onUpdate(bytesLoaded:Int, bytesTotal:Int), and onLoaded() , is very well documented in various places online.

I was wondering what the correct method of implementing a custom preloader is now ? There seems to be alot of preloader titled classes out there ? there is

openfl.display.Preloader, which overrides
openfl.display.DefaultPreloader and

is there one of these which works acreoss all targets like NMEPreloader did ?

For now NMEPreloader is (via a macro) a typedef to openfl.display.Preloader.DefaultPreloader which has the same basic functionality:

The deprecation warning could probably be clearer.

Create your own preloader, implement as many of the callbacks from IPreloader as you wish, I would recommend NOT extending the default preloader, use of the IPreloader interface is optional, but may be helpful

I’m open to other ideas that may seem less magical, like extending openfl.display.Loader, or a MovieClip with named labels?

So i’d need to extend openfl.display.IPreloader ? and override the functions as i’ve done before ? (unsure of the ‘callbacks’ terminology)

no new ideas, NMEPreloader seemed to do everying i could think a preloader would be needing !, and everything could be overridden and controlled !, so long as a user can control a) what happens when the loader starts, b) be informed of update progress, c) be informed of load being complete, d) being able to control how and when preloader exits - i can’t think of anything else it may need to do!

Are you using the custom preloader to change the way it looks, or just to listen to events for load progress?

I usually use my custom preloader to do a variety of things. - I customise the content being displayed during preloading, and if needed also do other things like showing sponsor animations, or preroll adverts whilst loading progresses ect.

At a minimum i always include a graphic showing what is loading, and a custom loading progress bar. and more often than not include a “Play” button to progress from the preloader once the loading is complete

when i include a “Play” button, i ensure it only appears once a) my desired preloading content/animation has finished, and b) everything that needs to be loaded has been loaded. (with NMEPreloader, clicking “play” called a function which removed everying and dispatched Event.COMPLETE)

Can anyone help me with working Preloader example?
I’ve update to the latest OpenFL/Lime versions and made my own Preloader like this:

class Preloader implements IPreloader extends Sprite


<app main="Main" file="..." path="bin" preloader="Preloader" />

So, trying to run game on Flash only calls new() function of my Preloader, but onInit(), onComplete and onUpdate are never called.
Did I miss something?
Thank you!

hi pozirk,

I’ve been wasting my morning trying to restore the same functionality as NMEPreloader, without NMEPreloader, and have so far only managed to get some of the functionality back for flash targets. (not html).

in my project.xml i have …

<app preloader="MyPreloader" />

and i’ve added unique listeners to MyPreloader, as follows

Lib.current.loaderInfo.addEventListener (, loaderInfo_onComplete);
Lib.current.loaderInfo.addEventListener (, loaderInfo_onInit);
Lib.current.loaderInfo.addEventListener (ProgressEvent.PROGRESS, loaderInfo_onProgress);

you can then check Lib.current.loaderInfo.bytesLoaded , and Lib.current.loaderInfo.bytesTotal to find out load progress (in flash, these come back as null in html weirdly, haven’t figure out how to restore any preloading within html yet).

Unfortunatly using this method you’ll also have no control over when your Main entry point is launched, unlike the NMEpreloader method which waited until you dispatched an Event.COMPLETE .

If anyone else has a working preloader for flash and html which can show simply load progress and give the developer control over when the Main entry point is launched, please do share !

Hey guys,

I just tried to create a custom preloader, it’s not fancy, but this worked:


import openfl.display.Sprite;

@:keep class Preloader extends Sprite {
	private var progress:Sprite;
	public function new () {
		super ();
		progress = new Sprite (); (0xFF0000); (0, 0, 100, 100);
		addChild (progress);
		progress.scaleX = 0;
	public function onInit ():Void {
		trace ("init");
	public function onLoaded ():Void {
		trace ("loaded");
		var delay = 60;
		addEventListener (Event.ENTER_FRAME, function (_) {
			if (delay == 0) {
				trace ("delayed start");
				dispatchEvent (new Event (Event.COMPLETE));
	public function onUpdate (bytesLoaded:Int, bytesTotal:Int):Void {
		trace ("update: " + bytesLoaded + "/" + bytesTotal);
		if (bytesTotal == 0) {
			progress.scaleX = 0;
		} else {
			progress.scaleX = bytesLoaded / bytesTotal;

FYI, currently OpenFL will skip the preloader on native builds, and will skip on Flash or HTML5 if it is already before it would initialize a preloader. We could possibly change this if there’s important logic in the custom preloaders, let me know.

I used <app preloader="Preloader" /> and tested on HTML5 to see the above work

I’m also open to ideas if you think the system can be improved, perhaps it should be something related to LoaderInfo? For example:

class Preloader extends Sprite {
	public function new (loaderInfo:LoaderInfo) {
		super ();
		loaderInfo.addEventListener (Event.COMPLETE, loaderInfo_onComplete);
		loaderInfo.addEventListener (ProgressEvent.PROGRESS, loaderInfo_onProgress);
	private function loaderInfo_onComplete (event:Event):Void {
		dispatchEvent (event);

Or perhaps (even better) have the loaderInfo set already, and don’t pass it in

class Preloader extends Sprite {
	public function new () {
		super ();
		loaderInfo.addEventListener (Event.COMPLETE, loaderInfo_onComplete);
		loaderInfo.addEventListener (ProgressEvent.PROGRESS, loaderInfo_onProgress);
	private function loaderInfo_onComplete (event:Event):Void {
		dispatchEvent (event);

What do you think?

Hi Joshua, thanks for your reply on this.

I’ve grasped parts of your preloader, and see that the functions onInit(), onLoaded, and onUpdate(bl:int, bt:Int) , are indeed triggered under html. (and work in a similar way to overriding NMEpreloader which is also still working there). I have a quick question regarding this, how would someone like me, be able to discover what the function names should be in a custom preloader if you weren’t here to write them on a forum for me ?

Your example does work for html, and it goes bring back the ability to trigger Event.COMPLETE when a developer is ready. It doesn’t however currently skip on native builds, the new() function of a custom preloader excecute on flash, neko, windows and mobile(android), just as a preloader created previously overriding NMEPreloader would do on all of those targets - however onInit(), onLoaded(), and onUpdate(bl:int, bt:Int) aren’t being triggered on any of those targets any more. and Event.COMPLETE is being dispatched without any developer control. Am i just describing a Bug ? and is this simple not working as Intended ?

My personal preference would be to go back to how things were. keep the entry in the project.xml, and have a single class to override if the developer wishes to update progress, or perform any further tasks before the main entry point is launched.

passing LoadeInfo to any preloader would be beneficial ! - in your html example above i cannot fathom where to query bytesloaded directly, and couldn’t find it other than within your onUpdate function - whereas for flash it can be queried at Lib.current.loaderInfo.bytesLoaded. (but always 0 on html)

Ah, you’re right – I didn’t realize that new was called even on native.

I’m leaning strongly toward a Sprite and an Event.COMPLETE dispatch when complete, then to handle progress, you can listen to it’s loaderInfo object. I think that would be even more Flash-like than the current system

Having LoaderInfo on hand would be nice, but I simply need it to work, preferably on all the targets :slight_smile:
Because now, with latest OpenFL/Lime. Preloader stopped working even in Legacy mode.

OpenFL 4 has no legacy :wink:

Does this work? :slight_smile:

Not on Flash. :confused: onInit, onLoad and onUpdate are not being called.
I should do the following to start it working:

Lib.current.loaderInfo.addEventListener(Event.COMPLETE, onLoaded);
Lib.current.loaderInfo.addEventListener(Event.INIT, onInit);
Lib.current.loaderInfo.addEventListener(ProgressEvent.PROGRESS, onUpdate);

But even with this I can’t control when to launch Main entry. Pretty much the same as @Penry wrote.
Or is it a new way of doing preloader now?

1 Like

OpenFL is designed to skip the preloader if things are already loaded

it’s just broken for flash at the moment it seems @pozirk. If we can get the functionality which @singmajesty has shown still works in html, back into flash, all would be good i think !!?

for neko and windows .exe files, there’s a single file to load, so there’s obviously no “preloading” going on once the first code has executed - once loaded it jumped through any preloader and proceeds to the main entry point - unfortunatly this is happening for flash at the moment, but i’m pretty sure now that is just a bug awaiting remedy ! - Should neko, windows and android completely omit a preloader ? even if it is set for those targets in the project.xml ? I’m undecided personally. - there seems little point in running code within a preloader, if it can be run within main once everything’s loaded !? but would removing the running of code within a defined preloader just cuase inconsistencies between targets for some projects ?

for android .apk , it would be fantastic if a preloader could exist!, i’ve never investigated how that is done, but if it were possible to create an android preloader, and have it defined as simply as overriding NMEPreloader was, that was be a huge benefit !

I am leaning strongly toward a change in OpenFL preloading

We use Sprite as base type, dispatch the progress events through the loaderInfo property, then wait for your preloader to dispatch Event.COMPLETE before we continue

It would be done on all platforms, and it would be up to you to decide when you dispatch COMPLETE, either immediately, or later.

The only thing is how to handle assets, if preloaders are easy to do, it raises questions of how to embed an image while preloading, before openfl.Assets is available

1 Like

In my preloader I was embedding images like this, it worked even on native platforms, although I am implementing preloader for native platforms differently.:

@:bitmap("assets/preload.jpg") class Back extends BitmapData {}
public function new()
 back = new Bitmap(new Back(,, PixelSnapping.AUTO, true);

similarly i’ve been using @:bitmap , (i add preloader assets to a /pre/ folder, which isn’t included within an assets path in the project.xml, so the graphics i use in the preloader dont also get added as Assets to the project as well !)

@:bitmap("assets/pre/preloadbar.png") class Pbar extends BitmapData { }