O'Reilly logo

Haxe Game Development Essentials by Jeremy McCurdy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required