Type.getClass error

trace(Type.getClass(new Sprite()));

error code:
Invalid field access : split
Called from openfl/_v2/events/EventDispatcher.hx line 166

For the record, here’s the line in question:


That error would be generated if full was null, and full would be null if Type.getClass (this) was null.

But that doesn’t explain why EventDispatcher.toString() is being called in the first place. Try adding the following on line 164:


(Revert it when you’re done, of course.)

By the way, what target are you compiling for? Neko?

i use haxe.macro.Context.onGenerate get class desc.
the Sprite className is "flash.display.Sprite"
but runtime i get Sprite className is “openfl._v2.display.Sprite”

is this a bug?

I found I was able to reproduce the error by running this:

var c:Class<Sprite> = Type.getClass(new Sprite());

Apparently Std.string() (which is also called by trace()) calls the toString() method when given a class. I don’t know how, but it calls an instance method without having an instance of the class.

And even though Std.is(this, EventDispatcher) is true, Type.getClass(this) returns null. (Yes, I tested all this.) The reason it returns null is because __dollar__objgetproto() returns null. I have no idea why that would be.

To work around the error, call Type.getClassName(Type.getClass(new Sprite())) if you want to trace it.

i use haxe.macro.Context.onGenerate functioin get Class desc
the Sprite typeName is “flash.display.Sprite”;
but runtime i get Sprite typeName is "openfl._v2.display.Sprite"
is this A bug?

That’s the real path of the class used, so not a bug.

First there’s a remap from flash.* to openfl.*, it’s like this since not everything in openfl is in flash, and some people thought that the classes in flash.* only worked on the flash target.

Second the “._v2” is because that target uses the old implementation (the new one isn’t ready for every target).

Yeah, my guess is that this is what Type.getClassName is for, perhaps tracing a class itself is unspecified depending on the target