- 3.1.3
- JavaScript 開発に使用
- jQuery に依存しまくり
install†
http://haxe.org/download
plugin†
haxelib install jQueryExtern
haxelib install createjs
エディタ†
IntellijIDEA
keybind
Settings -> Code Style -> Haxe
Wrapping and Braces
Keep when reformatting | |
Comment at first column | off |
ビルド設定†
project の設定で
- Compile with > HXML
- HXML file > build.hxml
build.hxml
-cp src
-main Main
-js ./html/test.js
-lib jQueryExtern
#--no-traces
- no-traces を付けると trace文が無視されるようになる
(それまではブラウザのコンソール等で見られる)
ハマりメモ†
JQueryStatic†
ごくまれにこれを使うとコンパイルが通らなくなることがある。
import 文が悪さをする模様
おそらく Haxe コンパイラのバグ
code snipet†
project の設定で
- Libraries => 「+」 => Haxe => c:\HaxeToolkit\haxe\lib\jQueryExtern
- 2.0.3 の source / class にチェックをいれてOK
- 名前が 2.0.3 のままになっているので jQueryExtern にかえる
JQuery の alias
private static inline function _(str:Dynamic):JQueryEX {return untyped $(str);}
private static inline function __(str:String):Dynamic {return untyped __js__(str);}
private static var _this(get, null):JQueryEX;
private static inline function get__this():JQueryEX {return untyped $(__js__("this"));}
html/index.html
<html>
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="test.js"></script>
</head>
<body>
</body>
</html>
src/Main.hx
package;
import js.JQuery.JqEvent;
import jQuery.JQuery;
import js.Browser;
class Main {
private static inline function _(str:Dynamic):JQuery {return untyped $(str);}
// haxe entry point ----
public static function main(){
_(Browser.window).ready(onReady);
}
private static function onReady(e:JqEvent){
new Main();
}
// ----
public function new(){
_("body").text("hello haxe");
trace("hello haxe trace");
}
}