Language Tags

MXHX defines certain special tags that represent language elements rather than Haxe types.

These MXHX language tags are defined by the MXHX language namespaces. Add a language namespace to the root tag to make these tags available. The example below uses the basic namespace:

xmlns:mx="https://ns.mxhx.dev/2024/basic"

Binding

The <mx:Binding> tag is used to create data bindings between two fields.

<mx:Binding destination="label.text" source="Std.string(slider.value)"/>

Alternatively, shorthand binding syntax with curly braces may be used instead:

<f:HSlider id="slider"/>
<f:Label id="label" text="{Std.string(slider.value)}"/>

Component

The <mx:Component> tag is used to define an inline component to assign to a field or property of type Class. It may also be used with a field or property typed as an abstract with a @:from method that can accept a Class value.

<f:ListView>
  <f:itemRendererRecycler>
    <mx:Component>
      <f:LayoutGroupItemRenderer>
        <f:AssetLoader/>
        <f:Label/>
      </f:LayoutGroupItemRenderer>
    </mx:Component>
  <f:itemRendererRecycler>
</f:ListView>

A separate class is generated for this inline component, and it includes a generated property named outerDocument, which references the outer component.

Declarations

The <mx:Declarations> tag is used to instantiate objects that should be stored in custom fields that are not defined on the component's superclass. Use the special id attribute to specify a name for each field.

<mx:Declarations>
  <mx:Float id="volume">88.4</mx:Float>
  <mx:Bool id="muted">false</mx:Bool>
</mx:Declarations>

The example above generates the following fields in Haxe:

public var volume:Float = 88.4;
public var muted:Bool = false;

Model

The <mx:Model> tag is used to generate anonymous structures from XML.

<mx:Model id="model">
  <root>
    <name>
        <first>Matt</first>
        <last>Murdock</last>
    </name>
    <company>Nelson and Murdock</company>
    <email>dd@example.com</email>
    <email>matt@nelsonandmurdock.example</email>
  </root>
</mx:Model>

The following object is generated from the above:

public var model:Any = {
  name: {
    first: "Matt",
    last: "Murdock"
  },
  company: "Nelson and Murdock",
  email: [
    "dd@example.com",
    "matt@nelsonmurdock.example"
  ]
}

Object

The <mx:Object> tag may be used as the root tag of a document when the generated Haxe class should not extend another class. This tag does not represent a concrete type in Haxe, meaning that a document with this root tag will not inherit any fields, methods, or other symbols from it. It cannot be detected using with Haxe reflection APIs, like Type.resolveClass() or Std.isOfType().

<?xml version="1.0" encoding="utf-8"?>
<mx:Object xmlns:mx="https://ns.mxhx.dev/2024/basic">
</mx:Object>

Note: In many programming languages (including Java, C#, and ActionScript), there is a built-in Object class that all other classes derive from (often implicitly, allowing declaration of a superclass to be optional). Haxe doesn't have this sort of universal Object class. However, since the root tag in MXHX cannot be omitted, and it is used to declare a superclass, a special tag is required to represent a class with no superclass. The Object tag was chosen because of the common naming convention mentioned above, but this doesn't create a new Object class in Haxe. It's a special tag only, like <mx:Declarations> or <mx:Component>.