How to give -swf-header informations from Haxe code?

78 views
Skip to first unread message

Aymeric

unread,
Jun 2, 2016, 8:05:20 AM6/2/16
to Haxe
Hi,

I'm looking for a way to remove my -swf-header args from my hxml and gives the parameters in plain Haxe code. How can I do that?

I tried that way without luck since addNativeArg isn't accessible from Flash target.
haxe.macro.Compiler.addNativeArg("-swf-header 900:650:60:003366");

JLM

unread,
Jun 2, 2016, 9:33:21 AM6/2/16
to Haxe
You would I believe have to hack the Ocaml code to achieve that in the manor you discribe, but it should be relatively straightforward to modify the complied swf after creation with a small additonal Haxe application. But I am sure there are many macro powers I am unaware of.

Aymeric

unread,
Jun 2, 2016, 9:58:47 AM6/2/16
to Haxe
Thanks for the quick answer. WelI I don't know macro neither, but I hope there is a solution there! Hacking Ocaml doesn't sound better for me since I don't know Ocaml at all ;)

Mark Knol

unread,
Jun 2, 2016, 11:24:17 AM6/2/16
to Haxe
Add this to your build.hxml or build command:
 --macro com.project.StartupUtil.execute()

Create a class com.project.StartupUtil with a public static function execute(), in this function you should be able to call Compiler.addNativeArg

I hope this works for you, I haven't tested it. Of course this does runs in compile-time (in macro-context), so you cannot access run-time variables

Aymeric

unread,
Jun 2, 2016, 11:45:02 AM6/2/16
to Haxe
Thanks for the answer Mark. Unfortunately, I got /usr/local/lib/haxe/std/haxe/macro/Compiler.hx:97: characters 10-48 : Unsupported platform

JLM

unread,
Jun 2, 2016, 3:50:30 PM6/2/16
to Haxe
I don't understand why you can't inject the header after compile?
https://github.com/HaxeFoundation/format/blob/master/format/swf/Reader.hx#L572
https://github.com/HaxeFoundation/format/blob/master/format/swf/Writer.hx#L96
It should be feasible to do that prior to opening, it should be feasible to add this into FlashDevelop or into the hxml file. 
But if you wanted to compile a special version of Haxe to always set a specific header I suspect it would be possible you could try changing:
https://github.com/HaxeFoundation/haxe/blob/development/src/generators/genswf.ml#L533

Aymeric

unread,
Jun 3, 2016, 4:38:48 AM6/3/16
to Haxe
Hmm interesting!

In my .hxml I've -swf-header 900:650:60:003366 using:
var swfInput = new haxe.io.BytesInput(haxe.Resource.getBytes("Main"));
trace(new format.swf.Reader(swfInput).readHeader());

I got: {nframes:1, fps:32512, height:650, width:900, compressed:true, version:28}. Why the fps isn't 60? Also the background color couldn't be read?

For writing I'm not sure if a SWF can overwrite itself?

JLM

unread,
Jun 3, 2016, 7:22:42 AM6/3/16
to Haxe
If you google for a hex editor you can view swf and you can alter the header manually even, it's perfectly possible.
https://mh-nexus.de/en/hxd/
you will see if you open a swf that has no compression that the first three letters give or take a letter are "swf", this is part of the swf header information.
https://github.com/HaxeFoundation/ocamllibs/blob/39f1f79b52fbc02d3b89cda6cad4f08dd88b849a/swflib/swf.ml#L262

I used to use [("stuff")] in my as3 to hide code from the flash compiler so that I could use new Flash IDE with new players without having to upgrade my flash, as often the player was launched before the IDE and just edit the swf header version in byte code editor for the feature to work.

Changing a header probably won't change the file length and checks involved, so you can literally create your own code to extract the header and then write it back to the front of the bytes/string.  For more complex stuff you might need to use more of the format library swf stuff to read and write stuff.  you might also want to look at swfmill, I have moved Jan's work from googlecode to my github because he seemed to have stopped working with Haxe but there is quite a lot of reading and writting swf stuff in there largely based on the format library that is interesting to play with.
Reply all
Reply to author
Forward
0 new messages