{"id":555,"date":"2012-02-17T17:19:46","date_gmt":"2012-02-17T16:19:46","guid":{"rendered":"http:\/\/www.aymericlamboley.fr\/blog\/?p=555"},"modified":"2012-02-17T17:23:37","modified_gmt":"2012-02-17T16:23:37","slug":"haxe-workflow-with-sublime-text-2-php-and-nme-examples","status":"publish","type":"post","link":"http:\/\/www.aymericlamboley.fr\/blog\/haxe-workflow-with-sublime-text-2-php-and-nme-examples\/","title":{"rendered":"haXe workflow with Sublime Text 2, Php &#038; nme examples"},"content":{"rendered":"<p>A good IDE is the developer&#8217;s best friend. <a href=\"http:\/\/fdt5.com\/\" target=\"_blank\">FDT<\/a> is my favorite one to code AS3 stuff, however I&#8217;m not very satisfied with haXe integration&#8230; it could be better. A good source code editor is also an amazing tool. I&#8217;ve found <a href=\"http:\/\/www.sublimetext.com\" target=\"_blank\">Sublime Text 2<\/a> some months ago, and it sounds always awesome to me.<a href=\"http:\/\/wbond.net\/sublime_packages\/package_control\" target=\"_blank\"> There is an extension<\/a> which add Package control management to ST2 for adding new plugin, like haXe one.<\/p>\n<p>Come on, download Sublime Text 2, install the Package control and haXe plugins!<\/p>\n<p>That&#8217;s ok ? Now we can create a simple Php project.<br \/>\nCreate a new file, save it as Test.hx and add this code :<\/p>\n<pre lang=\"actionscript3\">package;\r\n\r\nclass Test {\r\n\r\n    static function main() {\r\n\r\n    \tnew Test();\r\n    }\r\n\r\n    public function new() {\r\n    \t\r\n    \tvar number:Float = 4;\r\n        \r\n        trace(number + 5);\r\n    }\r\n}<\/pre>\n<p>Then press <em>ctrl<\/em> (even if you use a mac) <em>+ shift + b<\/em>. A new file called build.hxml is opened with some code generated to compile. You should just need that :<\/p>\n<pre># Autogenerated build.hxml\r\n\r\n# www\r\n-php www\r\n-main Test<\/pre>\n<p>Then press <em>ctrl + enter<\/em>. Your php files are generated. Pretty easy!<\/p>\n<p>Now let&#8217;s make more stuff, a PDO connection with a simple query.<\/p>\n<pre lang=\"actionscript3\">var cnx:Connection = PDO.open('mysql:host=localhost;dbname=igobelins', 'myUsr', 'myPwd');<\/pre>\n<p>If you press <em>ctrl + space<\/em> you have some greats auto-completion features! <em>ctrl + i<\/em> and the class is imported. If you make some mistake your code is highlighted in pink.<\/p>\n<p>Our php stuff :<\/p>\n<pre lang=\"actionscript3\" line=\"1\">package;\r\n\r\nimport php.db.Connection;\r\nimport php.db.Mysql;\r\nimport php.db.Object;\r\nimport php.db.PDO;\r\nimport php.db.ResultSet;\r\n\r\nclass Test {\r\n\r\n\tpublic var cnx:Connection\r\n\r\n    static function main() {\r\n\r\n    \tnew Test();\r\n    }\r\n\r\n    public function new() {\r\n\r\n      cnx = PDO.open('mysql:host=localhost;dbname=igobelins', 'myUsr', 'myPWd');\r\n\r\n      var sql:String = \"SELECT * FROM configs\";\r\n\r\n      var results:ResultSet = cnx.request(sql);\r\n       \r\n      for (result in results) {\r\n       \ttrace(result.user);\r\n       }\r\n\r\n       cnx.close();\r\n    }\r\n}<\/pre>\n<p>According that you have a field user in your database, it will show the names.<\/p>\n<p>Ok that was pretty cool, what about nme ? Go on <a href=\"http:\/\/www.joshuagranick.com\/blog\/?p=588\" target=\"_blank\">this page<\/a> and download the haXe project. In ST2 go in File\/Open Folder&#8230; and select the Folder you have just unzipped. It should show the different folders &#038; files in a left panel. Browse the Source and open SimpleBox2DExample.hx  and then press <em>ctrl + enter<\/em>. It is compiled for flash and open quickly the result in the Flash Player. Ok but with NME I would like to target cpp. No problem press <em>ctrl + shift + b<\/em> then select cpp and compile. This way you can quickly change the target.<br \/>\nHe wait, there isn&#8217;t html5 target !? I don&#8217;t know the reason but it is not offered. But you can add it (thanks to Julien Roche for the tips) : on Mac open the file Users\/YourUserName\/Library\/Application Support\/Sublime Text 2\/Packages\/HaXe\/HaxeComplete.py and add html5 to nme_targets on line 124. Restart ST2, press <em>ctrl + shift + b<\/em> select html5 then compile. You have a new target \ud83d\ude09<\/p>\n<p>Sublime Text 2 and the haXe plugin are awesome, but so far it can not be as powerful as an IDE for debugging. No breakpoint for example, anyway it is already a great tool for a simple code editor!<\/p>\n<p>Recently, JetBrains has released a haXe plugin for IntelliJ. We should keep an eye on it!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A good IDE is the developer&#8217;s best friend. FDT is my favorite one to code AS3 stuff, however I&#8217;m not very satisfied with haXe integration&#8230; it could be better. A good source code editor is also an amazing tool. I&#8217;ve found Sublime Text 2 some months ago, and it sounds always awesome to me. There &hellip; <a href=\"http:\/\/www.aymericlamboley.fr\/blog\/haxe-workflow-with-sublime-text-2-php-and-nme-examples\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">haXe workflow with Sublime Text 2, Php &#038; nme examples<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[70,106,44,6],"tags":[71,190,79,107,108],"_links":{"self":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/555"}],"collection":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/comments?post=555"}],"version-history":[{"count":3,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/555\/revisions"}],"predecessor-version":[{"id":557,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/555\/revisions\/557"}],"wp:attachment":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/media?parent=555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/categories?post=555"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/tags?post=555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}