Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get class name as string?

Tags:

haxe

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?

like image 251
Samir Sabri Avatar asked Feb 10 '15 15:02

Samir Sabri


1 Answers

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

like image 118
Mark Knol Avatar answered Sep 28 '22 09:09

Mark Knol