Haxe Preloader For Flash – Written in Haxe.

There has been some talk about creating flash preloaders for haxe. However, these methods step outside the haxe toolchain and add some additional complication.

I have come up with a reasonably simple method for creating a haxe preloader in haxe, and then linking to a (very almost) unmodified swf generated in haxe using a small neko program to produce a single file. The neko program uses code from the hxformat project, some of which is provided so you can easily recompile the tool.

Output.swf

Since each original haxe swf contains one frame, the resulting code
contains 2 frames. The first frame contains the preloader
which waits for the whole file to load and then locates the
PreloaderBoot class by name. This class runs the appropriate
initialisation code, creating and running the correct “main” class.

For classes that appear in both preloader and the main swf,
flash takes the first one – the one form the preloader. This means
that both classes will have the same “flash.Lib.current” and
(almost) everything will just work.

One complication comes from the fact that the flash.Boot class
is given a unique name for each of the swfs. This means flash.Boot
class in the main swf is not automatically “new”ed and placed
on the stage, and the standard haxe initialisation code is not
run. To compensate, we manually set the trace function and
call the Boot initialisation code explicitly.

This sounds a little dodgy to me, but it seems to work – I will
have to do some more testing.

The “Main” class in the example zip contains a resource to pad it out. The preloaded swf can be seen on it’s own screen. You can refresh to see it loading.

The example code is in
haxe-preloader-0.1.zip

All code & data there is public domain, except for the hxformat code,
which has its own license. Use at your own risk.

This entry was posted in flash, neko, Souce and tagged , , , . Bookmark the permalink.

5 Responses to Haxe Preloader For Flash – Written in Haxe.

  1. Matus says:

    Thanks for your script! It is something I was desperately looking for.

    One note, If I use the Preload.swf from your archive, everything works, but if I recompile the Preload.swf, the Output.swf breaks. Is the Preload.hx in the archive the same you were using?

  2. Huge says:

    I have a feeling haxe 2.03 may have broken this technique (the boot class processing changed). I will have to investigate and see if there is a fix.

  3. Pingback: haXe preloader « Create-ivity

  4. Drakim says:

    Any updates on this Huge?

  5. Huge says:

    Hi Drakim,
    Sorry, I think this solution is currently broken without compiler support for changing the flash.boot class. I’ll probably re-visit this in a couple of months.

    Hugh

Leave a Reply

Your email address will not be published. Required fields are marked *