SeanTierney

OpenFL – Part 1

April 26, 2014 Interactive Design / Development 0

Long have developers sought a way to crack the mystery of BODE (Build Once Deploy Everywhere). Now, there isn’t one perfect solution, yet, but OpenFL has made great strides to get us closer. I have been using OpenFL for a few months now and figured it was about time to put together a post that outlined the steps needed to get everything installed and running so that you can compile and test one of the sample applications.

For those who might be curious, I do most of my development on Mac, but I have included generic instructions with notes for OSX and Windows below.

What is OpenFL?
OpenFL is an SDK that lets you build games and applications to run on just about every device your users may have: Windows, Mac, Linux, iOS, Android, BlackBerry, Firefox OS, Tizen, Flash and especially HTML5. It is based on Haxe (pronounced ‘hex’ or ‘hacks’ depending on who you ask), which when compiled can be deployed as native code in a number of different languages and on a number of different platforms.

What is LIME?
Lime is an abstraction layer that makes it simple to go cross-platform with only one codebase; without the compromise of relying upon a scripting language or a virtual machine and provides the tools and the backend to seamlessly support many platforms. It uses the Haxe programming language, compiling directly to C++, JavaScript and others.

Installing OpenFL

1. download and install Haxe (you will need administrator rights to do this)
Windows – http://haxe.org/file/haxe-3.1.1-win.exe
Mac – http://haxe.org/file/haxe-3.1.1-osx-installer.pkg
Linux – http://www.openfl.org/haxe-3.1.1-linux-installer.tar.gz

Windows
The Haxe installer allows you to change the install directory, but we recommend that you use the default (“C:\HaxeToolkit”) rather than changing. Installing to another folder (specifically, “C:\Program Files”) can result in unexpected behavior, and break your install.

Mac
If you have any problems installing, you may need to allow applications that are not signed, or distributed from the Mac App Store. Go to System Preferences > Security & Privacy > General, and make sure the “Allow Applications” setting is set to “Anywhere”.

Onmce the installer is done running, opening up your terminal/command line and enter the following to set up Haxe, omit the quotes:

“haxelib setup”

Follow the on-screen instructions and keep your terminal/command line window open as it will be needed in the next step.

2. install lime
return to your terminal/command line window and perform the following steps, omit the quotes:

“haxelib install lime”

“haxelib run lime setup” -> be sure to say yes when prompted to install the command line shortcut as this will make your life easier

Follow the on-screen instructions and keep your terminal/command line window open as it will be needed in the next step.

3. now we can finally install openfl!!
return to your terminal/command line window and perform the following step, omit the quotes:

“lime install openfl”

Let’s run a sample project to see what the big deal is anyway…

We need to navigate to a location where we want to install some sample applications as well as create our own. I am going to recommend something simple like the following:

~/documents/openfl/samples

If the path does not exist, create the folders within your documents and then be sure to open your terminal/command line window and cd to the directory. If you are on a mac or linux, you can simply drag the samples folder to your terminal/command line window and press enter. To see the full list of samples that you can build, enter the following, omit the quotes

“lime create openfl”

We are going to use a very basic sample, Actuate, as our first test to show you how to install it as well as how to publish it for various platforms. Return to your terminal/command line window and perform the following step, omit the quotes:

“lime create openfl:ActuateExample”

So now what you ask? We have a sample installed but it doesn’t seem to do anything. Well, now we need to compile the code to work on any number of platforms. Let’s start with an easy one…FLASH…not, it’s not dead it is still going strong in many respects. So once again, return to your terminal/command line window and navigate to where your put your samples folder. Once there, we are going to cd into the ActuateExample and then run the following command, omit quotes:

“lime build flash”

You should see some work being done in your terminal/command line window and then it will return to your base prompt.

If you receive an error about “actuate” missing, you will need to run the following to correct the issue, omit quotes:

“haxelib install actuate”

now you can repeat the command above to install the sample, omit quotes:

“lime build flash”

If you look inside your ActuateExample folder you should now find an “Export > bin” folder and inside of that a brand new shiny .SWF file. Run this .SWF file in your swfPlayer and you will see a variety of colored balls bouncing around. Okay, so what, we built a Flash file…what if I am on a Mac and want to run a native application, well, there is a command for that as well. Again, be sure that you are inside the ActuateExample folder and run the following command, omit quotes:

“lime build mac”

Again, when the software is done running, look inside your export folder and you should now also see a mac64 > cpp > bin folder. You can run this application by double-clicking on it. For you windows people out there, run the same command and replace “mac” at the end with “windows” and you should get a native file as well.

Okay, so we have a Flash file and a mac file that run on the computer…so what. Well, we haven’t had to edit a single line of code, that’s what! You can run a whole bunch of app compilers and never have to change a line of code to do it:

windows
mac
linux
ios
android
blackberry
tizen
flash
html5

Now I can’t say that the design of whatever it is you are working on will look perfect in all of them the first time, but it will be pretty damn close.

So there we go. This is part one of what I hope will become a multi-part dive into OpenFL. Up next, how in the heck do you compile iOS and Android using OpenFL so stay tuned.