Preloader , now that NMEPreloader is depreciated

First, you should be able to remove “pixijs”, “openfl-tools” and “hxcpp” from the project.xml

Oops, the project.xml was pretty much taken from my template project, so forgot to comment/remove some stuff out of this test.

Seems it works nicely now. And I prefer the haxeflag hehe, since I plan to have a GUI for this later on and it’d pretty much be a project option.

Thanks for sharing your code! Made it a lot easier to debug

And no problem! Glad the code helped! C:

1 Like

Was there any resolution on Android Splash screens?

Maybe this article might be of some help :

It can be any resolution and any aspect rate :slight_smile:

10 posts were split to a new topic: Issue with embedded BitmapData

I meant solution - was there a solution to this so far?

Oh, sorry, at moment of writing answer I though about iOS splash screens.

As I know OpenFL doesn’t support android splash screens out of the box, but it is pretty easy to add it, if you have basic knowledge about Android programming.

You have to override Android template - put <template path="templates" /> into project.xml, than create folder templates and put here what you want to override. If you use macOS or *NIX, you can find original templates in /usr/local/lib/haxe/lib/lime/<lime version>/templates or /usr/lib/haxe/lib/lime/<lime version>/templates.

If you want to create splash screen like .gif in your prev. post, you basically need following folder structure:

|- /templates
|  |- /android
|     |- /template
|        |- /app
|           |- /src
|              |- /main
|                 |- /res
|                 |  |- /drawable
|                 |  |  |- splash.xml <- we will create it later
|                 |  |- /drawable-ldpi
|                 |  |  |- ic_splash.png <- we will create it later
|                 |  |- /drawable-mdpi
|                 |  |  |- ic_splash.png <- we will create it later
|                 |  |- /drawable-hdpi
|                 |  |  |- ic_splash.png <- we will create it later
|                 |  |- /drawable-xhdpi
|                 |  |  |- ic_splash.png <- we will create it later
|                 |  |- /drawable-xxhdpi
|                 |  |  |- ic_splash.png <- we will create it later
|                 |  |- /drawable-xxxhdpi
|                 |  |  |- ic_splash.png <- we will create it later
|                 |- /values
|                 |  |- colors.xml <- we will create it later
|                 |  |- styles.xml <- we will create it later
|                 |- AndroidManifest.xml <- copy from lime

Step 1

Modify AndroidManifest.xml - find android:theme="@android:style/Theme.NoTitleBar.Fullscreen" and change it to android:theme="@style/SplashTheme".

Step 2

Create styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="">
    <style name="SplashTheme" parent="@android:style/Theme.NoTitleBar.Fullscreen">
        <item name="android:windowBackground">@drawable/splash</item>

Step 3

Create splash.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="" android:opacity="opaque">
    <item android:drawable="@color/splash_bg" />
        <bitmap android:gravity="center" android:src="@drawable/ic_splash" />

Step 4

Create colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="">
    <color name="splash_bg">#cccccc</color> <!-- or put any color you want -->

Step 5

Take an image you want to be in center of splash screen, resize it to several resolutions (ldpi, mdpi, hdpi, xxhdpi, etc) and put to appropriate folders. Probably you can use some online or offline tool to do resizing for you.


That’s all. Few notes:

  1. I didn’t create additional SplashActivity here, because I think that for OpenFL it should work correctly even without it. But I’m don’t try it myself, so use it at your own risk :slight_smile:
  2. Actually I didn’t test it at all, so probably I can write something stupid here, but basically idea would be the same.

I thought splash screens were deprecated on Android

A pull request for Lime to add splash screen support would be nice if someone wanted to work on one :wink:

Google changed his mind :slight_smile: It called “Launch screen” -

IMHO lightweight apps doesn’t need splash screen, I never add splash screens to my own Android apps.

1 Like

embedding images using @:bitmap has stopped working for the HTML target using OpenFL 5.0.0 , still working correctly for Flash Neko and Windows targets… !

Could you try this change, and see if it helps?

I’ve tried it - no errors but nothing is loading.

BitmapData.fromBytes won’t work on HTML5 – at least, not instantly. If you do not rely upon bitmapData.width or bitmapData.height, I believe it should work once the image is loaded.

Otherwise, it is important to call loadFromBytes instead to wait asynchronously. I believe the @:bitmap embed adds an “onload” callback parameter as the final argument in the constructor on the HTML5 target, but I’d like to think of a better system long-term

Oh, I almost forgot :slight_smile:


<asset path="Assets/preloader" library="preloader" />
<library name="preloader" embed="true" />

Then I believe that should embed the files under “preloader” as it’s own asset library, which you can load inside of your preloader:

Assets.loadLibrary ("preloader").onComplete (function (_) {
    var bitmapData = Assets.getBitmapData ("preloader:image.png");

That’s an alternative to @:bitmap

Because embedding image using @:bitmap is broken for html5 target in openFl 5.x.x, I try to use your suggested method.
It works but with some different info.

<assets path="assets/preloader" library="preloader" />
<library name="preloader"  embed="true" />

But isn’t possible to get image just with


This works

 Assets.loadLibrary ("preloader").onComplete (function (_) {
   var bitmapData:BitmapData = Assets.getBitmapData("preloader:assets/preloader/logo.png");
   var bmp:Bitmap=new Bitmap(bitmapData);

full path to the bitmap should be written.

Thanks @restorer! Your solution worked nicely

Would be also interesting to see how to “hold” this windowBackground image until the preloader is at a certain stage. Right now basically the image is displayed quickly, and then the background color of openFL kicks in before the preloader is rendered.

Would be nice to be able to hold the graphic until ready for rendering. ( Maybe hold off on draw events or draw app with alpha 0 ? )

I have tried to use this preloader for HTML5 target:

package com;

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;

and at xml build file, I added <app preloader="com.Preloader" but all I see is a gray background which is defined at <window background="#eeeeee" I am using openFL 6.5.3 , please advice

Just guessing, i am not using a preloader:
Did you try “package;” and <app preloader=“Preloader”

Please look at the CustomPreloader example:

openfl create CustomPreloader
cd CustomPreloader
openfl test html5

It looks like this:

ProgressEvent.PROGRESS then Event.COMPLETE are dispatched as assets are loaded, then if the default is not prevented, Event.UNLOAD is dispatched and your preloader is removed. If you prevent the default, you can delay indefinitely, then dispatch Event.UNLOAD when you ready :slight_smile:

Thanks! by the way, the link above is broken

Oh! Sorry, I just moved it :blush:

Its ok :slight_smile: