Skip to content Skip to sidebar Skip to footer

Access External Javascript Libraries Using Haxe

I'm trying to figure out how to access external JavaScript libraries from Haxe. Should the source file for the extern class be in the same folder as the corresponding native JavaSc

Solution 1:

The Extern mechanism assumes that the defined types exist at runtime (they are available to be invoked/used) but assumes nothing about how and where those types are defined. This is true for all the platforms.

How the extern libraries are included in your project mostly depends on the target and can vary greatly.

In the case of JS, there is not a direct association between the extern definitions (.hx files) and the JS that includes those types (js library). The haxe files should be accessible by haxe (using -cp, -lib, or putting them in your source directory) while the js files should be accessible by the runtime (include the lib JS in your HTML before the haxe generated code).

What might create some confusion is that Haxe supports a feature that allows you to embed an external js file inside the generated code. This way you can distribute only one file instead of a main file + one or more lib files. You can have a look at how Haxe automatically includes JQuery in __init__().

Post a Comment for "Access External Javascript Libraries Using Haxe"