Haxe編譯工具原來的目的是合成一些web技術到一種語言。支持Flash,JavaScript,和Neko,web開發者可以使用Haxe編譯工具來使用這三種技術而不用學習新的語法。 而且,因為Haxe,Flash,JavaScript和Neko可以在Windows,Mac OS和Linux上進行開發,許多開發者就可以使用Haxe而不用改變他們喜好的操作系統。
隨著時間的推移,更多技術的橋接也被開發出來。 基于Neko的一個重點,Haxe語言可以被進一步增強,而不用以任何方式修改編譯工具。這通向其他令人興奮的開發,比如SWHX(ScreenWeaver for Haxe)框架使用一個Flash GUI(Graphical User Interface)層來創建桌面應用,也可以使用我們自己的Neko Media Engine(NME),封裝了 Simple DirectMedia Layer(SDL)框架和函數作為一個2D游戲API。
這里的重點是,Haxe編譯工具并不是一項新技術,僅僅是一個程序,用來轉換一種新的語言到一些舊的技術中。
使用Haxe的好處是極大的,但是可以概括為下面幾點:
* 使用現有的技術發揮它們最大的能力。
* 開發者之間的界限降低,提供更多的合作空間
* 開發團隊之間的知識增加,因為他們編寫代碼延伸到他們同行的技術
* 項目迅速建立,并且有更少的錯誤和平臺障礙
* 項目更容易維護,因為所有團隊成員都能理解語言語法而不用理解部署的技術
* Haxe類為一種技術開發,然后可以很容易的編譯到另一個技術.
## 編譯到Flash
Flash是一個不錯的平臺。事實的確如此,作為最流行的web多媒體平臺,沒有其它工具可以撼動它的位置,很難為其找到一個競爭者(譯者注:如今HTML5的發展勢頭已經超過Flash)。以其在許多機器和操作系統下的能力,可以肯定的說Flash在未來一段時間內仍將如此。盡管傳言稱微軟的新的開發技術會威脅到它。
The Flash IDE, synonymous to developers who create Flash movies, contains its own version of a Flash file compiler, as does the new Flex Builder application from Adobe. These tools are probably the forerunners in commercial Flash development, but are not needed to create complete Flash applications.
Since the introduction of ActionScript 2.0 — the scripting language behind Flash movies — developers have had the ability to write applications using pure code. Unfortunately, though, the Flash IDE is not the most ideal environment for building Flash files in this way, as it is aimed primarily at designers. Flex provides a better solution, but still has drawbacks.
If you contemplate both Flash and Flex and their relative language syntax — ActionScript 1 and 2 for the Flash IDE and MXML & ActionScript 3 for Flex Builder — you will see two very different programs and languages compile to the same platform. Granted, the Flash IDE compiles to Flash versions 9 and below (ActionScript 1, 2, and 3) whereas the Flex Builder IDE compiles to Flash version 9 alone (ActionScript 3), but they inherently perform the same feat. haXe is able to perform the same routine of compiling from a source language syntax to the Flash byte code specification, much like the Flash IDE and Flex Builder, except that haXe is able to compile a single language to both the complete Flash 6 to 8 specifications and the Flash 9 specification. That ’ s pretty impressive in our book (pun intended).
haXe makes all of this possible by providing a language that is loosely coupled to the output, which is why it is able to support so many platforms. All haXe needs to understand is which equivalent structures for each platform map to the haXe structures and how it should be serialized in the output file.
The Flash SWF file, which is one such output, is a document containing a series of codes in the form of bytes. Each byte represents media, functions, variables, or properties that make up the content of the movie and describe to the Flash virtual machine (or player) the exact content and functionality of the movie. When compiling to Flash, haXe produces the same SWF output and provides all of the same features as the official Flash compilers produced by Adobe, though of course, certain functions within the haXe library may not be supported depending on which version of Flash you are compiling against. You can handle this using compiler directives that allow different portions of code to be compiled depending on the target technology。
For those of you who are used to the MTASC compiler by Nicolas Cannasse for ActionScript versions 8 and below, haXe steps in as the successor, reducing further development of the MTASC compiler to bug fixes only.
When MTASC (Motion - Twin ActionScript Compiler) was released several years ago, many developers saw, for the first time, their first break into the world of Flash. Previously, many developers would complain that the Flash IDE was far too geared toward the designer and left little leverage for the developer. MTASC changed all of that by offering an all - code entry point using tools they were already familiar with.
haXe follows this developer - friendly route, though with its powerful yet friendly syntax, it also offers designers the chance to tinker in the world of the developer.
## 編譯到JavaScript
JavaScript has been around for some time, but for client - side browser scripting, there is no competition. While Internet Explorer provides access to the Visual Basic scripting interpreter, JavaScript is still the only scripting language supported by the majority of browsers, and so is the only choice for thousands of developers worldwide.
Each of the well - known browsers supports quite a variation of the JavaScript API. The most noted differences are those between the Internet Explorer JavaScript engine and the Mozilla JavaScript engine, which have been the source of much pulling of hair for web developers everywhere for a number of years. When you build applications that rely heavily on client - side scripting over various browser types, it is a necessity to include numerous hacks and tricks to avoid facilitating functionality that performs well on some browsers, yet poor on others. When compiling to JavaScript with the haXe compiler, haXe provides a set of functions that form a small framework for maintaining suitable cross - browser JavaScript functionality.
## 編譯為Neko
Haxe編譯到Neko字節碼格式,這和處理Flash字節碼的方式類似。編譯后的文件被Neko虛擬機使用,同樣和Flash虛擬機的形式類似,雖然一些用戶的支持必須使用一些第三方庫。
Usually, one would write for the Neko virtual machine for the purpose of creating server - side web logic using the mod_neko module or to create a desktop application for use in a command console or batch file. Using third - party modules, it is also possible to create desktop applications and full network ready server frameworks of any scale.
Although not much has been mentioned yet about the Neko language, compiler, and virtual machine, they do form a fairly substantial part of this book. The Neko framework is discussed in detail in Chapter 9 , “ Building Websites with haXe. ”
- 本書目錄
- 第一章:Haxe介紹
- 互聯網開發的一個問題
- Haxe是什么,為什么產生
- Haxe編譯工具
- Haxe語言
- Haxe如何工作
- 那么Neko是什么
- Haxe和Neko的必須條件
- 本章摘要
- 第二章:安裝、使用Haxe和Neko
- 安裝Haxe
- 使用Haxe安裝程序
- 在Windows上手動安裝Haxe
- Linux上手動安裝Haxe
- 安裝Neko
- Windows上手動安裝Neko
- 在Linux上安裝Neko
- Hello world! 一式三份
- 編譯你的第一個Haxe應用
- 你的程序如何編譯
- HXML編譯文件
- 編譯到Neko
- 編譯為JavaScript
- 程序結構
- 編譯工具開關
- 本章摘要
- 第三章:基礎知識學習
- Haxe層級結構
- 標準數據類型
- 變量
- 類型推斷
- 常數變量
- 簡單的值類型
- 浮點類型
- 整型
- 選擇數值類型
- 布爾類型
- 字符串類型
- 抽象類型
- Void 和 Null
- 動態類型
- unknown類型
- 使用untyped繞過靜態類型
- 注釋代碼
- 轉換數據類型
- Haxe數組
- Array
- List
- Map
- Haxe中使用日期時間
- 創建一個時間對象
- Date組件
- DateTools類
- 操作數據
- 操作符
- Math類
- 使用String函數
- 本章摘要
- 第四章:信息流控制
- 數據存放之外
- 條件語句
- if語句
- switch語句
- 從條件語句返回值
- 循環
- while循環
- for循環
- 循環集合
- Break和Continue
- 函數
- 類的函數
- 局部函數
- Lambda類
- 本章摘要
- 第五章:深入面向對象編程
- 類和對象
- 實例字段
- 靜態字段
- 理解繼承
- Super
- 函數重載
- 構造器重載
- toString()
- 抽象類和抽象方法
- 靜態字段,實例變量和繼承
- 繼承規則
- 使用接口
- 高級類和對象特性
- 類的實現
- 類型參數
- 匿名對象
- 實現動態
- Typedef
- 擴展
- 枚舉
- 構造器參數
- 本章摘要
- 第六章:組織你的代碼
- 編寫可重用代碼
- 使用包
- 聲明一個包
- 隱式導入
- 顯式導入
- 枚舉和包
- 類型查找順序
- 導入一個完整的包
- 導入庫
- Haxe標準庫
- Haxelib庫
- 其他項目中的庫
- 外部庫
- 使用資源
- 文檔化代碼
- 離線文檔
- 在線文檔
- 單元測試
- haxe.unit包
- 編寫測試
- 本章摘要
- 第七章:錯誤調試
- trace函數
- trace輸出
- haxe的trace和ActionScript的trace
- 異常
- 異常處理
- CallStack和ExceptionStack
- 異常管理類
- 創建完全的異常處理類
- 異常類代碼
- 本章摘要
- 第八章:跨平臺工具
- XML
- XML剖析
- Haxe XML API
- 正則表達式
- EReg類
- 模式
- 定時器
- 延遲動作
- 隊列動作
- MD5
- 本章摘要
- 第九章:使用Haxe構建網站
- Web開發介紹
- Web 服務器
- 使用Web服務器發布內容
- HTML速成課程
- Haxe和HTML的區別
- NekoTools Web Server
- Apache安裝mod_neko
- Windows安裝Apache和mod_neko
- Linux安裝Apache和Mod_Neko
- 第一個Haxe網站
- 使用Neko作為網頁Controller
- neko.Web類
- Neko作為前端控制器
- 本章摘要
- 第十章:使用模板進行分離式設計
- 什么是模板
- Template類
- Template語法
- 使用資產
- 何時在模板中使用代碼
- 服務器端模板的Templo
- 安裝Templo
- 使用Templo
- haxe.Template和mtwin.Templo表達式上的區別
- Attr表達式
- Raw表達式
- 邏輯表達式
- 循環表達式
- set, fill, 和 use表達式
- Templo中使用宏
- 手動編譯模版
- 第十一章:執行服務端技巧
- 第十二章:使用Flash構建交互內容
- 第十三章:使用IDE
- 第十四章:通過JavaScript制作更多交互內容
- 第十五章:通過Haxe遠程通信連接所學
- 第十六章:Haxe高級話題
- 第十七章:Neko開發桌面應用
- 第十八章:用SWHX開發桌面Flash
- 第十九章:多媒體和Neko
- 第二十章:使用C/C++擴展Haxe
- 附加部分