Começando com Haxe/JS
Developing Javascript code is really easy with Haxe. Let's see our first HelloWorld sample :
class Test { static function main() { trace("Hello World !"); } }
Put this class into a file named Test.hx and create the file compile.hxml in the same directory with the following content :
-js test.js -main Test
To compile, you can simply double-click on the compile.hxml file (or run the command haxe compile.hxml). If an error occur, it will be displayed. If everything went smoothly like it should, this will produce a file named test.js that can be embedded into an HTML page such as this one :
<html> <head><title>Haxe JS</title></head> <body> <div id="haxe:trace"></div> <script type="text/javascript" src="test.js"></script> </body> </html>
If you put since code into a file named test.html and open it with your webbrowser, it should display Hello World with information about file and line the trace occured. Please note that a div block is needed to display the Haxe Javascript traces.
Using Alert
The possibility to display some text is to use alert. Modify Test.hx with the following content :
class Test { static function main() { js.Lib.alert(js.Lib.window.location.href); } }
Compile and open the test.html. It should display a window message box displaying the current location URL.
Watch the available APIs from Lib .