Archives by Month

January

2013

How to Embed assets in Haxe, like in ActionScript

Sometimes trying to find a simple thing is really hard when you are learning a new language. Something most of us have to do for every project that is writen in Actionscript is to embed assets. 

The Actionscript way

[Embed(source=“myimage.png”)]

private var MyImageBM:Class;

Here is the Haxe way

@:bitmap(“myimage.png”)class MyImageBM extends BitmapData {}

var bm = new Bitmap(new MyImageBM(100,100));

BareBones MVC

An extremely light MVC framework built in Haxe.

A quick history: In late 2012 I was on a project building some games for IR5. It was a really good experiance because it was my first go at using the Starling framework for Actionscript.
The client had build the framework we where using to build the games around using Parsley. Parsley has been my MVC framework of choose for the past few years. I came to like IOC and Injection, however we found that the games themself ran faster and more smooth if we went for a simple “handrolled” MVC of our own and stay away from the Event driven nature of Flash.
Starling works so well that we found that responce to changes in data for the game where much faster by using a plain old publish subscribe method and allow our views to “register” with the data model and allow our data model to call “update” on any views that are subscribed to it. Old School plain Jane MVC if you will.
I have Steff Kelsey, the lead developer on the project to thank for coming up with the simple sturcture and conventions we used.
BBMVC is a direct result of the work that we did on these games. I liked it so much that I started using in on all my projects and figured the best thing I could do is create a reusable lib that is cross platform via a haxelib
More to come on BBMVC and examples soon. Stay tuned. If you have any qustions in the mean time please feel free to hit me up. @matthewswallace on twitter.

 

Haxe Introduction

Haxe (pronounced as hex) is an open source programming language

While most other languages are bound to their own platform (Java to the JVM, C# to .Net, ActionScript to the Flash Player), Haxe is a multiplatform language.

It means that you can use Haxe to target the following platforms :

  • Javascript : You can compile a Haxe program to a single .js file. You can access the typed browser DOM APIs with autocompletion support, and all the dependencies are resolved at compilation time.
  • Flash : You can compile a Haxe program to a .swf file. Haxe is compatible with Flash Players 6 to 11. Haxe offers very good performance and language features to develop Flash content.
  • NekoVM : You can compile a Haxe program to NekoVM bytecode. This can be used for server-side programming such as dynamic webpages (using mod_neko for Apache) and also for command-line or desktop applications, since NekoVM can be embedded and extended with some other DLL.
  • PHP : You can compile a Haxe program to .php files. This enables you to use a high level strictly-typed language such as Haxe while keeping full compatibility with your existing server platform and libraries.
  • C++ : You can generate C++ code from your Haxe source code, with the required Makefiles. This is very useful for creating native applications. The NME library uses this to run Haxe code on iOS, Android, etc. As of 2.10 it also includes debugging.
  • C# and Java: You can generate source code for these targets new as of 2.10 (note this is still experimental, with better support coming in Haxe 3.0.

The idea behind Haxe is to let the developer choose the best platform for a given job. In general, this is not easy to do, because every new platform comes with its own programming language. What Haxe provides you with is:

  • a standardized language with many good features
  • a standard library (including Date, Xml, Math…) that works the same on all platforms
  • platform-specific libraries : the full APIs for a given platform are accessible from Haxe

Haxe is useful for many different reasons. You might be wondering why use Haxe?

Want to learn more about Haxe ? Access the documentation.

If you are interested in taking this corse then submit your email. I'll make sure you get a discount for signing up early.