So in the final build, I put a Browser.alert call (traces don’t appear to trigger in final) in the getter, in the constructor, and in the function calling the getter (“myFunc”).
The correct order should be: constructor, myFunc, getter.
The order that I’m seeing is: myFunc, getter,
Since the constructor is not getting called, it is clearly the case that the variable is null. Also noting that this behaves as expected in a debug or release build. The constructor is triggered via Type.createInstance().
The code is essentially this:
public var name(get,null):String;
private function get_name(): String { return myVal.getName(); }
function new ( val: EnumValue ) {
myVal = val;
}
private function myFunc(): Void {
trace( "name= " + name );
}
Update1: Pretty sure I’ve found the problem. In a final build, Type.createInstance() doesn’t function. When I trace the object, it only shows as empty “{ }”. When I manually called ‘new MyClass()’ where I could, then the game runs correctly in final mode. However, anywhere else where Type.createInstance() is used, it fails to create a new class. It is weird that it knows the correct function to call in that class (so maybe it is creating the structure?), but it definitely does not call the constructor ever.
Update2: I noticed that Type.createInstance() is used all over the place in openfl (like Type.createInstance(DocumentClass,[]) ), and those seem to be working. So for measure, here’s my function that is called where I see Type.createInstance failing to trigger the class constructors, in case it’s something I’m doing to make it fail.
function createState( id: EnumValue, t: Class<IGameState> ): Void {
var state = Type.createInstance( t, [ id ] ); // new SomeClass( id );
}
Update3: I tried a very simple example of Type.createInstance() and confirmed the same behavior there, too.
//Main.hx
var t = Type.createInstance( TestClass, [] );
Browser.alert( t ); //final: { } //release: { someStr:TEST CLASS STR, m_int:22 }
t.debug(); //final: { undefined, undefined } //release: { TEST CLASS STR, 22 }
//TestClass.hx
public var someStr:String;
private var m_int:Int;
public function new() {
someStr = "TEST CLASS STR";
m_int = 22;
}
public function debug(): Void {
Browser.alert( someStr + ", " + m_int );
}