elimak

Combining Cocktail Haxe with PhoneGap

Last April at the “World Wide Haxe conference 2012“, Yannick Domiguez and Alex Hoyau from Silex-labs presented Cocktail, a cross-platform library.
As I joined forces with the team of Silex-Labs aka Intermedia for a few weeks, I decided to dive into their resource.

………………………………………………………………………………………………………………………………………………….
COCKTAIL
………………………………………………………………………………………………………………………………………………….
Cocktail is divided in 2 parts with a “core” which is platform independent, and a “port” which is target specific. Its is then possible to compile the same code for Actionscript and Js without any conditional compilation.
This allows developers to create their applications on multiple devices and OS.

Cocktail API can be compiled and packaged for

  • mobiles and tablets (iOS, Android, BlackBerry…)
  • desktop computers (Windows, Mac, Linux)
  • televisions (Google TV, Adobe Air for TV, HbbTV (european smart TV standard))
  • all major browsers, in HTML5 with a Flash fallback
  • PHP, in order to be able to generate and manipulate the client “view” on the server side

………………………………………………………………………………………………………………………………………………….
SMALL DEMO
………………………………………………………………………………………………………………………………………………….
For this post I created a small proof of concept – Thanks to Raphael Harmel aka Codam for his help – to demonstrate how you can package the same code for mobile devices with 2 different options:

You can download the source here

:::: JS + PhoneGap ::::

- Compile the sources using build/HelloWorld_js.hxml
- Zip together all the files included in the bin folder with the exception of helloworld.swf and helloworld_air.xml.
- Go to https://build.phonegap.com/ (requires registration)
- Create a new app using the option “upload an archive or index.html file” and download your installer to test it on your device.
- Note that you need an Apple Developer Program (costs 99$), and an Apple provisioning file + an Apple p12 certificate to generate the iPhone/iPad installer.

:::: SWF + Air wrapper ::::

- Compile the sources using build/HelloWorld_as.hxml
- Wrap the helloworld.swf into an *.apk and an *.ipa file using helloworld_air.xml as manifest.
- Note that you will need the Air SDK and the Java JRE.
- Follow the help from Adobe to package your swf using Air.

Ha(xe)ppy coding!

Leave a Reply

You must be logged in to post a comment.