Haxe to OpenFL to iOS
Important Note: This guide is a results of research I did trying to get an OpenFL app to work on iOS. There was many websites and resources I had to use, I hope this one stop shop helps those looking to get this process to work properly without having to spend days browsing the web!
To get started, install Haxe globally on your system:
With the latest versions of Haxe and Neko installed, open a command-prompt (Windows) or terminal (macOS/Linux) and run these commands:
Install Haxelib (The Haxe Package Manager)
sudo haxelib install openfl
Install OpenFL (OpenFL applications can be written in Haxe, JavaScript (EcmaScript 5 or 6+), or TypeScrypt, and may be published as standalone applications for several targets including iOS, Android, HTML5(choice of Canvas, WebGL, SVG or DOM), Windows, macOS, Linux, WebAssembly, Flash, AIR, PlayStation 4, PlayStation 3, PlayStation Vita, Xbox One, Wii U, Tivo, Raspberry Pi, and Node.js.)
haxelib run openfl setup
lime and hxcpp will also be installed. Lime (command-line tools. provide the backbone for delivering projects to each target platform). HXCPP (C++ source, Haxe calls the HXCPP library, which includes a standard C++ library to enable unique Haxe features, and calls the target compiler toolchain. This is needed to target iOS and standard native toolchain for other platforms, such as the Android NDK when targeting Android.)
In order to check if OpenFL has been installed properly, run:
openfl
You can use the “openfl create” command for a list of available samples.
openfl create
For example, here is how to build and run the DisplayingABitmap sample on HTML5:
openfl create DisplayingABitmap
cd DisplayingABitmap
openfl test html5
Next, compile to C++ using:
openfl test cpp
(This will take a while the first time)
Now lets try building to iOS
First download Xcode and install the SDK along with the current command line tools
We need to add IPHONE to the System compiler:
sudo vi /private/var/www/hxcpp/3,4,188/src/hx/libs/std/Sys.cpp
In the int _hx_std_sys_command method add IPHONE to the OR statement like this:
#if defined(HX_WINRT) || defined(EMSCRIPTEN) || defined(EPPC) || defined(IPHONE) || defined(APPLETV) || defined(HX_APPLEWATCH)
Save and close file. Go back to your project folder.
Launch app within Xcode to complete configurations
openfl update ios -xcode
Xcode will open with your project. If you see any build warning, click the warning then click “Perform Changes”
In the Build Target, select the one you need. I just use the most recent.
Press Play Button to build and deploy
Done!