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 ...

Get Haxe Game Development Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.