Convert Haxe to AS3

This question might sounds weird to most of you but I need to push an update on iOS for an app I’ve originaly done using Adobe AIR and I’m in a hurry (this app has to be published today (it won’t obviously)).
I still can’t manage to publish it on iOS, that’s why I’m thinking of rewrite it in AS3 and do it the way I’ve been doing it the past 5 years. When I’ll have time I’ll try to figured out and how to publish it on iOS, but I’ve already spend way too much time on it ans can’t afford to make my client wait anymore :frowning:

Is there a tool like as3hx to convert a haxe package to as3 or do I have to do it manually.

I’ve seen this haxe : haxe -as3 command line but I’m not sure how to use it (and if it’s still maintain).

Here’s the basics of the command (which I think you have probably seen):

http://old.haxe.org/doc/flash/as3gen

but it’s possible there is a class or two you still need to make it compile. Did you find out why you were getting a white screen? Would it make a difference to package using a different iOS application type? Were there any other debug messages you got back from the device? Thanks!

EDIT:

You could also try using embed="false" on your assets, and loading them as you ordinarily would at runtime using a Loader, BitmapData.loadFromFile or other asynchronous methods. Perhaps AIR is unhappy somehow about how we embed the asset files into the SWF?

EDIT2:

Have you tried “DisplayingABitmap” on the device, such as:

openfl create DisplayingABitmap
cd DisplayingABitmap
openfl test ios -air -verbose

…does it have the same problem, or does it run?

EDIT 3:

I’m trying to test on iOS, locally, but I can’t get the provisioning profile to work. Everything I have seems to give an error saying it is too old of a profile

EDIT 4: (sorry for the ongoing edits!)

You might also consider openfl test ios if you have a Mac you can use for a native build

Yes I’ve seen it already :slight_smile: but I guess it won’t work in my case, it seems to check like a compilator if the code is using method that can be translated or not. I’m using some very openFL / HTML5 specific classes, and it raise error without event try to translate.

I just wanted a tool like as3hx, to save time recreating classes and classes structure without checking for class dependencies and compatibility.

Regarding my attempt to compile for AIR iOS, I didn’t find why I had this white screen (not fullscreen white though)
I guess it’s probably because I’m using libs that are not compatible with AIR.
I’m using:

  <haxelib name="openfl" />
  <haxelib name="actuate" />
  <haxelib name="robotlegs" />
  <haxelib name="swiftsuspenders" />
  <haxelib name="msignal" />
  <haxelib name="starling" />
  <haxelib name="ash" />
  <haxelib name="yaml" />
  <haxelib name="tjson" />
  <haxelib name="air3" />
  <haxelib name="akifox-asynchttp" />

I’ll give a try to your suggestion on EDIT 2

I have tried to run openfl test ios also.
I don’t have a Mac, I test on a virtual machine, maybe that’s why I have no luck yet. It compile but I can’t pass the splash screen.It’s really hard to debug I have to rebuild each time I make a compile, it takes like 5min to compile and test each time I change something (is there a better way to test/debug by the way?)

Thanks a lot for your help,you rocks :slight_smile:

PS: if you want an access to try by yourself I can give you one…

I’d be happy to give it a try, but I suppose the provisioning profile would have to be such that it would work for my device? Going to the simulator is not working for me, (probably) since the AIR SDK might not be updated for the iOS 11 SDK, yet

For build times, maybe it would be possible to use another iOS target? Maybe ipa-debug-interpreter?


http://help.adobe.com/en_US/air/build/WS901d38e593cd1bac35eb7b4e12cddc5fbbb-8000.html

There’s also a chance it might give more feedback on errors

Oh, I could try a native iOS build, certainly. Oh, it’s possible (I’m not sure) the “air3” library might be messing with something in the build. I’d recommend removing that – Lime should have better AIR extern support than the old “air3” library

Yes, this is still maintained, and it’s likely what you want to use. At least for now. When you have more time, by all means try to get an OpenFL-based solution up and running, but it sounds like right now you just need AS3 code based on your Haxe code.

The thing to understand is that Haxe is primarily a source-to-source compiler. That is, Haxe’s main feature is to take Haxe code and produce the equivalent source code in another programming language.

When you run openfl test android, Haxe doesn’t compile the Android app. Haxe just turns your source code into the equivalent C++ code. Then OpenFL passes that C++ code to the Android build tools, and those tools create the actual Android app. Haxe does nothing more than translate Haxe code into C++ code; other tools handle the rest.

You might be wondering why I’m going on and on about this one little thing. All I’m saying is, Haxe has one job*, and it is very good at that job. You can absolutely tell Haxe “convert my Haxe code to AS3 code,” and Haxe will create working code. (It won’t be pretty code, but it will definitely work.)

*Well, one main job. In addition to source-to-source compiling, Haxe can create entire Flash, Neko, and HashLink apps.


So how do you do this? Well, start by opening up the command line and typing “haxe.”

> haxe
 Usage : haxe.exe -main <class> [-swf|-js|-neko|-php|-cpp|-cppia|-as3|-cs|-java|-python|-hl|-lua] <output> [options]
 Options :
  -cp <path> : add a directory to find source files
  [...]
  -swf <file> : compile code to Flash SWF file
  -as3 <directory> : generate AS3 code into target directory
  [...]
  -main <class> : select startup class
  -lib <library[:version]> : use a haxelib library
  -D <var[=value]> : define a conditional compilation flag
  [...]

It’s a lot to take in, but the short version is that it wants you to provide a main class, an output type and directory, and a class path where it can find your Haxe files.

And you can absolutely do it that way:

> haxe -main com.example.Main -as3 Export/as3 -cp Source

But you’d also have to add a -lib flag for every library you use (including OpenFL), and then define who knows how many compilation flags. Luckily, there is another way.

Since OpenFL uses Haxe, OpenFL has to define all these arguments itself. Fortunately for you, it leaves a record of the arguments it used. Open up your Export/ios folder, and whatever other folder(s) are inside that (at a guess, it might go Export/ios/air/release, but it doesn’t matter if not). When you find a set of three folders named bin/, haxe/, and obj/, you’ll know you’re in the right place.

Open the haxe/ folder and then open release.hxml. (If your computer asks what program to use, pick any text editor.) Notice that release.hxml is one big list of command line arguments for Haxe. Haxe accepts this kind of file instead of actual command line arguments, and release.hxml happens to be set up to make Haxe compile your code correctly (including all libraries and compilation flags).

You only need to make one little change. Near the end of the file should be a line saying something like -swf Export/ios/air/release/bin/AppName.swf. This is the line telling Haxe that the final product is a .swf file, but you can replace it with “-as3 Export/as3,” which tells Haxe that the final product should be AS3 code.

The last step is to run Haxe. Don’t run OpenFL, because it will overwrite your changes. You want to run Haxe directly.

Open up your command line window again, and navigate to the root of your project. You should be in the folder containing project.xml, the Source/ folder, and the Export/ folder. Now you need to type out the path from here to release.hxml, like so:

> haxe Export/ios/air/release/haxe/release.hxml

It’ll take a while, but once it’s done, check under Export/as3 for all of your code in AS3 format.

2 Likes

This is a great explanation, I just wanted to add that you will have to avoid certain OpenFL-specific features (such as how we embed assets), unless you also -swf-lib and include our generated “assets.swf” file.

Hi,

Thanks for the great explaination!

I followed all the steps you describe, but I’m having an error: (I guess I’ll have many other after this one).

src/starling/display/materials/Program3DCache.hx:19: characters 42-70 : Invalid number of type parameters for flash.utils.Dictionary

Is there a way to avoid this or did I miss a param somewhere?

Look at our HXML when we target the Flash target. I think you are missing a reference to -cp path/to/openfl/externs/core/flash, which provides our own externs for the Flash target, such as making some changes/additions to how Flash Dictionary works

I use the file generated when targeting Flash
(I can’t actually compile having the same error in FD)

-main ApplicationMain
–macro openfl._internal.utils.ExtraParams.include()
-cp C:/HaxeToolkit/haxe/lib/openfl/6,2,2
-D openfl=6.2.2
–macro lime.Lib.extraParams()
-cp C:/HaxeToolkit/haxe/lib/lime/5,7,1
-D lime=5.7.1
-cp C:/HaxeToolkit/haxe/lib/actuate/1,8,7
-D actuate=1.8.7
-cp C:/HaxeToolkit/haxe/lib/robotlegs/0,4,2
-D robotlegs=0.4.2
-cp C:/HaxeToolkit/haxe/lib/swiftsuspenders/0,2,1
-D swiftsuspenders=0.2.1
-cp C:/HaxeToolkit/haxe/lib/msignal/1,2,4
-D msignal=1.2.4
-cp C:/HaxeToolkit/haxe/lib/starling/1,8,11
-D starling=1.8.11
-cp C:/HaxeToolkit/haxe/lib/ash/1,5,4/src
-D ash=1.5.4
-cp C:/HaxeToolkit/haxe/lib/yaml/1,3,0
-D yaml=1.3.0
-cp C:/HaxeToolkit/haxe/lib/tjson/1,4,0
-D tjson=1.4.0
-cp C:/HaxeToolkit/haxe/lib/akifox-asynchttp/0,4,7
-D akifox-asynchttp=0.4.7
-cp src
-cp C:\HaxeToolkit\haxe\lib\openfl/6,2,2/externs/core/flash
-cp C:\HaxeToolkit\haxe\lib\openfl/6,2,2/externs/core/openfl
-D native-trace
-D tools=5.7.1
-D flash-use-stage
-D no-compilation
-D openfl-flash
-D web
–macro include(‘com.myproject.project.app.view’)
-cp bin/flash
-as3 bin/as3
-cp bin/flash/haxe

I just removed everything about -swf and replace it by the -as3 line

-swf-lib obj/assets.swf
-swf-version 17
-swf bin/flash/bin/MyProject.swf

It seems to me that openfl/externs/core/flash is referenced :confused:

keep these two:

-swf-lib obj/assets.swf
-swf-version 17

Still no luck :frowning:
Sorry for being so problematic :slight_smile:

-main ApplicationMain
–macro openfl._internal.utils.ExtraParams.include()
-cp C:/HaxeToolkit/haxe/lib/openfl/6,2,2
-D openfl=6.2.2
–macro lime.Lib.extraParams()
-cp C:/HaxeToolkit/haxe/lib/lime/5,7,1
-D lime=5.7.1
-cp C:/HaxeToolkit/haxe/lib/actuate/1,8,7
-D actuate=1.8.7
-cp C:/HaxeToolkit/haxe/lib/robotlegs/0,4,2
-D robotlegs=0.4.2
-cp C:/HaxeToolkit/haxe/lib/swiftsuspenders/0,2,1
-D swiftsuspenders=0.2.1
-cp C:/HaxeToolkit/haxe/lib/msignal/1,2,4
-D msignal=1.2.4
-cp C:/HaxeToolkit/haxe/lib/starling/1,8,11
-D starling=1.8.11
-cp C:/HaxeToolkit/haxe/lib/ash/1,5,4/src
-D ash=1.5.4
-cp C:/HaxeToolkit/haxe/lib/yaml/1,3,0
-D yaml=1.3.0
-cp C:/HaxeToolkit/haxe/lib/tjson/1,4,0
-D tjson=1.4.0
-cp C:/HaxeToolkit/haxe/lib/akifox-asynchttp/0,4,7
-D akifox-asynchttp=0.4.7
-cp src
-cp C:\HaxeToolkit\haxe\lib\openfl/6,2,2/externs/core/flash
-cp C:\HaxeToolkit\haxe\lib\openfl/6,2,2/externs/core/openfl
-D native-trace
-D tools=5.7.1
-D flash-use-stage
-D no-compilation
-D openfl-flash
-D web
–macro include(‘com.myproject.project.app.view’)
-cp bin/flash
-swf-lib obj/assets.swf
-swf-version 17
-as3 bin/as3
-cp bin/flash/haxe

Where does starling/display/materials/Program3DCache.hx come from? I don’t see it in our repository anywhere

Good bet,

This is coming from the Graphic extension I ported a while ago.

I’ve done it really quick when targeting HTML5, that’s probably why it has some compatibility pb…

Does importing openfl.utils.Dictionary make a difference?

If that still fails, you could try using Map instead

Yes it does :slight_smile:
I replaced all the flash.utils.Dictionary by openfl.utils.Dictionay.
I can compile to HTML5 but I’m having an error on the OpenFL Dictionary Class when targeting flash:
C:\HaxeToolkit\haxe\lib\openfl/6,2,2/externs/core/openfl/openfl/utils/Dictionary.hx:536: characters 28-51 : Invalid number of type parameters for openfl.utils.Dictionary

For now, can you comment out this line, or swap it out for Map<IShader, Dynamic> = new Map<IShader, Dynamic> () instead?

I don’t really see what to change, this line is actually some kind of Class, if I comment this line, I have to comment the whole block but… Never mind I finally got it working on iOS, Hurrah!!!

Thank you very much for your help, I must say I’m impress by your reactivity and this framework which offers awesome performances, on iOS too :slight_smile:

1 Like