7

How would I get the class name in string?

I tried this:

Type.getClassName(this));

Where this is the current class I am in, but I got error:

com.SubWidget should be Class<Dynamic>

Any help?

Samir Sabri
  • 937
  • 3
  • 11
  • 26

1 Answers1

13

You should pass a Class to Type.getClassName. So, first grab that using Type.getClass, like this:

http://try.haxe.org/#6A196

class Test {
    static function main() new Test();

    function new()
    {
        var className = Type.getClassName(Type.getClass(this));
        trace('Current class name = $className');
    }
}

Also see: http://api.haxe.org/Type.html#getClassName

Mark Knol
  • 9,663
  • 3
  • 29
  • 44