This article shows you how to get started with the Haxe version of Away3D Lite.
VIEW THE DEMO
DOWNLOAD THE SOURCE CODE
Away3D Lite has introduced support for Haxe, which is an open source programming language that can compile to a number of platforms including Flash, JavaScript, C++, Neko and PHP. Currently Away3D Lite Haxe only supports compiling to Flash, but projects like GameHaxe are working on capability layers that may eventually lead to Away3D Lite being able to be compiled and run using C++ (with SDL) and JavaScript (with the Canvas element).
Getting started with Away3D and Haxe is not difficult, but it does require a few steps that may not be obvious for ActionScript developers looking to make the move to Haxe. This article will step you through the process of creating your first Away3D Haxe application.
Your first step is to get a decent Haxe IDE. Despite its name, FlashDevelop also supports Haxe. FlashDevelop can be freely downloaded from its website here.
You will also need to download and install Haxe. The Haxe download page includes installers for Windows, Linux and MacOS. The download page also lists some of the IDEs that are available with support for Haxe.
With Haxe and FlashDevelop installed, open up Flash Develop and create a new Haxe AS3 project. This can be down by selecting Project | New Project.
Type in a name and a location for the project and click the OK button.
Your new project will consist of a single file called Main.hx. Overwrite the contents of this file with the following code:
package ;
import flash.Lib;
class Main
{
Haxe is kind of like Java or C# in that it requires a static function as the entry point to the application. This is a little different to what ActionScript developers will be used to, because ActionScript can use any class that extends the Sprite class as the entry point.
static function main()
{
GettingStarted is a class that we will create that initializes the Away3D Lite engine and adds a primitive 3D object to the scene. Later tutorials will use classes with different names, and the line below will have to be updated with the name of those new classes.
Lib.current.addChild(new GettingStarted());
}
}
The code that is used to initialize the Away3D Lite engine will be included in a class called GettingStarted. To create a new class right click on the src folder and select Add | New Class...
Then type in GettingStarted.hx into the Add New Class dialog box.