Comparison of Code
Documentation
> Getting started
> Getting started with Haxe/Flash
> Migrating AS3 to HaXe
> Comparison of Code
(scroll down for Haxe version)
AS3
//Package package { //Imports import flash.display.* import flash.events.* //Class definition public class Main extends MovieClip { //Class fields & types private var array:Array = ["hello", 10] private var boolean:Boolean = true private var integer:int = -10 private var uinteger:uint = 10 private var number:Number = 10.5 private var object:Object = {foo:'bar'} private var string:String = '13' //Properties private var _sampleProperty:Object; public function get sampleProperty():Object { return _sampleProperty; } public function set sampleProperty(value:Object):void { _sampleProperty = value; } //Constructor public function Main() { var _str:String = String(integer); var _int:int = int(string); for(var i:int=0; i<array.length; i++) { trace(array[i]);//Hello,World } with (object) { foo=10; } test('a');//a, b (falls through because of the missing break statement) } //Methods private function test(param:String):void { private function test(param:String):void { switch (param) { case "a": trace("a"); case "b": trace ("b"); break; default: trace ("Neither") } } } } } //Private classes?
compile with:
mxmlc Main.as -output MovieAS3.swf
HAXE
//semicolons are mandatory //Package package;// no curly braces for package //Imports import flash.display.MovieClip;// no wildcard for imports import flash.events.Event; import flash.Lib; //Class definition class Main extends MovieClip// no 'public' keyword here { //Class Fields & types // no variable instantiation outside functions private var array:Array<String>;//Arrays are typed private var boolean:Bool; private var integer:Int; private var uinteger:UInt; private var number:Float; private var object:Dynamic; private var string:String; //Properties private var _sampleProperty:Dynamic; public var sampleProperty(getSampleProperty, setSampleProperty):Dynamic; public function getSampleProperty() { return _sampleProperty; } public function setSampleProperty(value:Dynamic) { _sampleProperty = value; } //Constructor public function new()//constructor name is always 'new' { super();// super is mandatory array = ["hello", "world"]; boolean = true; integer = -10; uinteger = 10; number = 10.5; object = {foo:'bar'}; string = '13'; var _str:String = Std.string(integer); var _int:Int = Std.parseInt(string); for(i in 0...array.length) { trace(array[i]);//hello,world } for(i in array) { trace(i);//hello, world } //with(object){foo=10}// the with keyword is not available in Haxe test('a');//a (no break statements in the switch-case statements) } //Methods private function test(param:String):Void // Void (with capital) { switch (param) { case "a": trace("a"); case "b": trace ("b"); default: trace ("Neither"); } } /***********************************************************************************************************************/ //To tell the FlashPlayer what script should be run when opening the swf //you need to supply a 'main entry point'. See the compiler argument -main below. public static function main() { flash.Lib.current.addChild(new Main()); } /***********************************************************************************************************************/ } //Private classes?
compile with:
Main
-main Main
-swf9 MovieHaxe.swfMain : tells the compiler what class(es) must be compiled
-main Main: tells the compiler that the main entry point for the swf can be found inside the class Main
-swf9 MovieHaxe.swf: tells the compiler to generate an 'AS3-swf file' named MovieHaxe.swf
This page lists all the compiler arguments:
http://haxe.org/doc/compiler
version #7273, modified 2009-11-20 14:46:22 by tylermac