Hi!
I am newbie in Haxe. I try to port my as3 Starling game to OpenFl/Starling.
I need some help to understand Haxe)
This is a part of my game windows manager. It works on as3. I cut all unnecessary code.
class WindowType
{
public var _name:String;
static public final WINDOW_BATTLE_INFO = new WindowType("WINDOW_BATTLE_INFO");
static public final WINDOW_CONFIRM = new WindowType("WINDOW_CONFIRM");
public function new(name:String):Void
{
_name = name;
}
public function toString():String
{
return _name;
}
}
class BaseWindow extends Sprite implements IWindow
{
public var Type:WindowType;
function get_Type():WindowType
{
throw ("must be overriden!");
}
}
class ConfirmWindow extends BaseWindow
{
override function get_Type():WindowType
{
return WindowType.WINDOW_CONFIRM;
}
}
class MainClass extends Sprite
{
private var _currentWindows = new Map<String, BaseWindow>();
public new():Void
{
super();
showWindow(WindowType.WINDOW_CONFIRM);
}
public function showWindow(type:WindowType):Void
{
var mcWindow:BaseWindow = WindowsFactory.getWindow(type);
mcWindow.addEventListener(Event.ADDED_TO_STAGE, onWindowAddedChangeListener);
this.addChild(mcWindow);
}
private function onWindowAddedChangeListener(e: Event): Void
{
var win:BaseWindow = cast e.currentTarget; // I check that 'win' is 'ConfirmWindow'
_currentWindows[win.Type.toString()] = win; // Uncaught TypeError: Cannot read properties of null (reading 'toString')
}
}
I get win.Type == null in last string. Why?)