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
- 附加部分