[Solved]Compiler says "Class x has no field y", but it actually does.



  • Hey guys, I don't know if this is more of an Haxe problem, but oh well.
    The problem I'm having is that I have a class named Enemy and it has a static variable named rating.
    Here is the problem:
    if I use

    Enemy.rating;
    

    the compiler does everyting fine, but if I use

    public var x:Class<Enemy> = Enemy;
    ...
    x.rating;
    ...
    

    the compiler gives me an error that says Class<Enemy> has no field rating, while it actually does. Does anybody know how to fix this problem?
    (Note that this isn't actual code, it's a semplification of the issue)



  • Did you mean:

    var x: Enemy = new Enemy();
    ...
    x.rating;
    ...
    


  • Nope, I mean what I typed.



  • Alright, so Twitter user @FoxelBox solved the problem. I'm posting here on the forum so that people having the same problem have the solution :)

    Reflect.field(x, "rating");
    

    This will return what I expected x.rating to return.


Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.