How to get class name as string?
Asked Answered
Q

1

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?

Quinque answered 10/2, 2015 at 15:2 Comment(2)
this.getClass().getName()Indreetloire
@alfasin it should be noted that that only works if you have "using Type;" in the imports at the top of your file.Seashore
P
14

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

Priest answered 10/2, 2015 at 15:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.