This tutorial shows you how to create a simple PHP application using HAXE and FlashDevelop.
DOWNLOAD THE SOURCE CODE
Haxe is somewhat unique amongst programming languages. Typically when you write an application it is either compiled to a native executable, or compiled at run time to a virtual machine like Java, DotNet or PHP. Haxe is different. A program written in Haxe is instead compiled into source code for a target language like JavaScript, PHP, Flash, Neko or C++. This means that this one language can be run in a web page, on a web server or as a native executable.
So why would you bother with yet another programming language? As an example, using the Haxe language exclusively you can compile a PHP application to run on your server, compile some JavaScript to be run on the client web browser, and even compile a Flash applet to embed in the web page. This combination of PHP, JavaScript and Flash is not uncommon, and would normally require code written in 3 different languages, probably with 3 different IDEs. With Haxe you have one language and one IDE for all three technologies.
Depending on your existing programming experience, you may even find the Haxe language preferable. The code is similar to most of the other "C" style languages out there like C++, Java, C# and ActionScript.
In this tutorial we will create a simple PHP application use Haxe.
FlashDevelop is a free and very capable IDE, which you can download from here.
You will also need a copy of Haxe, which you can download from here.
Create a new FlashDevelop project by clicking Project->New Project...
Create a new Haxe PHP project.
FlashDevelop will create an initial class called Main for you. Rewrite the class with the code below.
class Main
{
static function main()
{
php.Lib.print('Hello World!');
}
}
Click the Build Project button in the toolbar. This will compile the code into the PHP files that your web server will use.
It is worth using Haxe just for the ability to compile the code. In languages like PHP and JavaScript especially, being able to pick up syntax errors at compile time saves a lot of time.
Include the bin folder created in the FlashDevelop project folder in your web servers path, and point a browser to the index.php file.
Haxe is a free and powerful technology that blurs the lines between a lot of popular web technologies like JavaScript, PHP and Flash. There is also quite a large collection of community Haxe libraries to help get you started, which you can find here.
Return to the Tutorial Index