Pulling string data from XML
To get string data out of XML, we're going to create a singleton class that can be accessed anywhere to get at the strings and constants for each string's ID.
Building the Strings class
To start, create a new class in the ui
folder named Strings
. This class won't extend anything, and it should be in the ui
package.
Here's what it should look like to start:
package ui; class Strings { public function new() {} }
Next, add the following imports:
import haxe.xml.Fast; import openfl.Assets;
The new class in use here is the Fast
class, which is Haxe's XML handling class.
After this, add the code needed to use this class like a singleton:
public static var instance(get, null):Strings; private static function get_instance():Strings { if(instance == null) { instance = new Strings(); } return instance; }
This works exactly like the singleton setup in the SoundManager
class does. As such, we'll also need to make our constructor private:
private function new()...