Since the Haxe programming language originated from an ActionScript 2.0 compiler, there are many similarities between the languages. In fact, a number of the minor differences between ActionScript 3.0 and Haxe can be explained if you understand this heritage.
However, as you look deeper, you will find that Haxe is a modern, strictly-typed language that takes inspiration from many of the best parts of ActionScript while adding many new and valuable features.
¶Basic Types
¶ActionScript 3
1 | Boolean |
¶Haxe
1 | Bool |
¶Package Declarations
¶ActionScript 3
1 | package com.example.myapplication { |
¶Haxe
1 | package com.example.myapplication; |
¶Defining a Class
¶ActionScript 3
1 | public class MyClass { |
¶Haxe
1 | class MyClass { |
¶Loops
¶ActionScript 3
1 | for (var i:uint = 0; i < 100; i++) { |
¶Haxe
1 | for (i in 0...100) { |
¶Switch Statements
¶ActionScript 3
1 | switch (value) { |
¶Haxe
1 | switch (value) { |
¶Type Inference
¶ActionScript 3
1 | var hi = "Hello World"; |
¶Haxe
1 | var hi = "Hello World"; |
¶Type Casting
¶ActionScript 3
1 | var car:Car = vehicle as Car; |
¶Haxe
1 | var car:Car = cast vehicle; |
¶Type Details
¶ActionScript 3
1 | if (vehicle is Car) { |
¶Haxe
1 | if (Std.is (vehicle, Car)) { |
¶Checking for Null
¶ActionScript 3
1 | if (object == null) { |
¶Haxe
1 | if (object == null) { |
¶Hash Tables
¶ActionScript 3
1 | var table:Object = new Object (); |
¶Haxe
1 | var table = new Map<String,Int> (); |
¶Rest Parameters
¶ActionScript 3
1 | function test (...params):void { |
¶Haxe
1 | function test (params:Array<Dynamic>) { |
¶Reflection
¶ActionScript 3
1 | var foo = object["foo"]; |
¶Haxe
1 | var foo = Reflect.field (object, "foo"); |
¶Constants
¶ActionScript 3
1 | private const gravity:Number = 9.8; |
¶Haxe
1 | private inline static var gravity = 9.8; |
¶Function Types
¶ActionScript 3
1 | function hello (msg:String):void { |
¶Haxe
1 | function hello (msg:String):Void { |
¶Getters and Setters
¶ActionScript 3
1 | function get x ():Number { |
¶Haxe
1 | public var x (get, set):Float; |
¶Read-Only Properties
¶ActionScript 3
1 | function get x ():Float { |
¶Haxe
1 | public var x (default, null):Float; |
¶Missing Features
Haxe does not currently support custom namespaces, and methods do not provide an arguments property.
¶Additional Features
In addition to most of the features of Actionscript 3, Haxe includes support for enums, type parameters (generics), structures, typedefs, custom iterators, conditional compilation, inlining and more.
仇贝 (my psychological doctor)