[haXe] Changing "Using HAXE from AS2" into "Using HAXE from HAXE"

Nicolas Cannasse ncannasse at motion-twin.com
Thu Apr 20 21:38:57 CEST 2006


> Hello,
> 
> I'm Eddy de Boer from The Netherlands, new in HAXE land.

Hi Eddy,


> 		class AS2Test {
> 		    var mcl : MovieClipLoader;
> 		    function AS2Test() {

In haXe, the class constructor is always called "new".

> 		         var me = this;
> 		         flash.Lib._root.createEmptyMovieClip("haxe_mc",0);
> 		         mcl = new flash.MovieClipLoader();
> 		         mcl.onLoadInit = function() { me.onInit() };

in haXe, there is automatic delegate creation, so you don't need "me"
and you can directly write mcl.onLoadInit = onInit;

> 		         mcl.loadClip("haxe.swf", flash.Lib._root.haxe_mc);
> 		    }
> 
> 		    function onInit() {
> 		        var test = new flash.Lib._root.haxe_mc.Test(55);

You can't use "new" with an arbitrary expression.
You can replace it by using the Reflect API :

var test = Reflect.createInstance(flash.Lib._root.haxe_mc.Test,[55]);

> 		        flash.Lib._root.createTextField("tf",1,0,0,100,100);
> 		        flash.Lib._root.tf.text = test.foo();
> 		    }
> 		}

The other things should work.

Nicolas



More information about the Haxe mailing list