A utility type that allows methods to accept multiple types, when dealing with "future" FlxStates. Prior to haxeFlixel 6, FlxG.switchState and other similar methods took a FlxState instance which meant FlxStates were instantiated before the previous state was destroyed, potentially causing errors. It also meant states with args couldn't be reset via FlxG.resetState. In version 5.6.0 and higher, these methods now take a function that returns a newly created instance. This allows the state's instantiation to happen after the previous state is destroyed.

examples:

You can pass the state's contructor in directly:

FlxG.switchState(PlayState.new);

You can use short lambas (arrow functions) that return a newly created instance:

var levelID = 1;
FlxG.switchState(()->new PlayState(levelID));

You can do things the long way, and use an anonymous function:

FlxG.switchState(function () { return new PlayState(); });

[Deprecated] Lastly, you can use the old way and pass in an instance (until it's removed):

FlxG.switchState(new PlayState());
Available since

5.6.0

.

See also:

Static methods

@:fromstaticfromMaker(func:() ‑> FlxState):NextState

@:fromstaticfromState(state:FlxState):NextState

staticgetConstructor(this:Dynamic):() ‑> FlxState