Haxe Reflection and Type

I see that couple people have problem when using Reflection feature on haxe. I'm also. I couldn't find why my code below didn't work as I expected [quote] var scenehandler = new SceneHandler(); var scene = Type.createInstance(Type.resolveClass("S…

Viewing 1 to 4 (4 Total)
Haxe Reflection and Type

misugijunz

misugijunz
Total Posts: 8
Joined: June 22, 2012

I see that couple people have problem when using Reflection feature on haxe. I'm also.

I couldn't find why my code below didn't work as I expected


var scenehandler = new SceneHandler();
var scene = Type.createInstance(Type.resolveClass("SplashScreen"), [scenehandler]);


it always return that it can't be instantiated for a non constructor one. and I also check that it returns null for this code


trace("test: " + Type.getClassName(Type.resolveClass("SplashScreen")));


SceneHandler, Scene, SplashScreen class are in the same package,

SplashScreen is extending Scene.
SplashScreen and Scene constructor is containing one argument a SceneHandler.

I read documentation on Haxe. It is neeeded that class Scene, SplashScreen to be compiled first before reflection can take effect. I mark the both sources as always compile in FlashDevelop but no luck. Any suggestion?

Tags:
Posted on June 22, 2012 at 10:15 PM

Huge

Huge
Total Posts: 547
Joined: October 07, 2011

Re: Haxe Reflection and Type

Hi,
I think you need to include the package in the string-name, even though it is in the same package. The string does not "know" which package it is in, it is just a string.

Hugh

Posted on June 25, 2012 at 1:30 AM

misugijunz

misugijunz
Total Posts: 8
Joined: June 22, 2012

Re: Haxe Reflection and Type

Yeah, I tried but no works.
I changed back to non reflection by specify the class directly.

Posted on July 04, 2012 at 5:17 AM

jfroco

jfroco
Total Posts: 10
Joined: April 14, 2012

Re: Haxe Reflection and Type

Hi,

Try importing SplashScreen explicitly in the class you are using reflection:

package;
import SplashScreen;
...
var scenehandler = new SceneHandler();
var scene = Type.createInstance(Type.resolveClass("SplashScreen"), [scenehandler]);

Posted on July 27, 2012 at 6:05 PM