As some of you may know, I have been getting into haXe reccently. For those of you dont know what haXe is, this is taken from haxe.org:
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.
I have been aware of haXe for a long time, infact I used to make extensive use of precursor to haXe, MTASC the alternative compiler for AS2. Since the launch of AS3 however, Nicolas Cannasse of Motion-Twin has moved onto HaXe, and the project has flourished.
I have used HaXe in the past for various small projects, usually to take advantage of some of the features that the language offers Flash developers that AS3 cant offer us. Features such as function inlining and the fast memory ops mean that flash developers can really get some great performance out of their libraries while at the same time still able to compile to SWC’s.
Recently I have been exploring the various other targets offered by haXe, not just the flash one. Currently haXe supports the following targets:
Flash : You can compile a haXe program to a .swf file. haXe is compatible with Flash Players 6 to 10, with either “old” Flash 8 API or newest AS3/Flash9+ API. 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 will enable you to use a high level strictly-typed language such as haXe while keeping full compatibility with your existing server platform and libraries.
So now, finally to the point of this post. I sat down to write the core functionality of the crawler. To do the URL crawling so far I had been using jQuery’s get() method to load an external page.
How was I to use the jQuery library in haXe I wondered. Well thankfully this has already been thought of with the special “extern” keyword: http://haxe.org/doc/js/extern_libraries
It wasnt long however before I ran into a compilation issue when I tried to use the static function get() on the JQueryS class:
characters 2-9 : Unknown identifier : JQueryS
This confused me as no matter what I did, I couldn’t get the haXe compiler to recognise the class. Having spent an evening stuck on the problem I decided to email the creator of the project Andy Li.
It turns out that to beable to use the JQueryS class you must first import the JQuery class:
Low and behold that worked!
As I couldn’t find the solution to this problem on a Google search I thought I would write up the solution myself so that others don’t stumble on this rather singular gotcha.