Swf lib generate="true" with SimpleButton


I’m currently migrating a project from haxe target flash to openfl in order to be able to compile to other target.
I know that it’s not magical. And I need to go step by step.

I first succeded to compile by using some haxe flags to add all my swf libs (haxeflag name="-swf-lib)

It generate a swf of 3.3mo, I added a custom preloader but it started to show only when 2.4Mo were already loaded (so this is a bit late)

To fix this I thought that it was due to the -swf-lib haxe flag that doesn’t fit the openfl asset flow. So I started to use the Assets class. But there is a lot of code to change and the swf haxelib seems to prevent all this changes and also enable the html5 and C++ compilation. So I’m trying it.

I made a simple test

project.xml :

<app main="Main" file="main" path="bin" preloader="preloader.Preloader" />
<window background="#6090BE" fps="24" />
<window width="800" height="480" unless="mobile" />
<window orientation="landscape" vsync="false" antialiasing="0" if="cpp" />

<haxelib name="openfl" />
<haxelib name="actuate" />
<haxelib name="swf" />

<assets path="assets/preloader" include="*" if="web" />
<assets path="assets/swf" include="*" />

<library path="assets/swf/main.swf" preload="true" generate="true"/>

main.hx :

class Main extends Sprite
public function new()

  Lib.current.stage.scaleMode = StageScaleMode.NO_SCALE;
  Lib.current.stage.align = StageAlign.TOP_LEFT;
  var mc = new BusyCursor();
  mc.x = 100;
  mc.y = 100;


this is working fine!

But if I replace BusyCursor which is a MovieClip by ButtonNext ( a SimpleButton )
It doesn’t compile

I have these compilation errors :

bin/flash/haxe/assets/ButtonNext.hx:23: characters 2-21 : Not enough arguments
bin/flash/haxe/assets/ButtonNext.hx:12: lines 12-25 : Missing super constructor call

And looking at the generated code :

class ButtonNext extends SimpleButton {
	public function new () {
		if (!SWF.instances.exists ("libraries/main/main.swf")) {
			SWF.instances.set ("libraries/main/main.swf", new SWF (Assets.getBytes ("libraries/main/main.swf")));
		var swf = SWF.instances.get ("libraries/main/main.swf");
		var symbol = swf.data.getCharacter (389);
		super (cast symbol);	

We can see that only one parameter is given to the super call whereas the format.swf.instance.SimpleButton is looking for 2 parameters.

Am I doing something wrong? Does the SimpleButton class is not supported?

Thank you for helping

It sounds like this might be a little bug in how the “generate” code works for SimpleButton, MovieClip is much more regularly tested. Do you see how we can fix it?


Thank you for your answer. I fixed like this :

Done a pull request on this change.
It does the job for the flash target but doesn’t compile for html one and throw a cast error for windows target.
I have also seen that there is no SimpleButton class for SWFLite. I don’t know exactly what is SWFLite and his purpose but SimpleButton just can’t work with it.

I forgot the idea of using swf lib to migrate our game. I will change all the swf assets libs to use png. It will be a big work. we will continue to target flash during this time.
But I’m still stuck with the preloader issue. It only shows when 2.3mo are already loaded. Is there a trick to display it sooner?