Have you ever had an issue where the name of your class doesn’t match up with the output in Haxe? I know I have, and there is a simple fix for this issue, which will help you when creating libraries, APIs, and bindings to other libraries in separate languages.


In Haxe, there are tags known as metadata tags. These allow you to do several things to the code based on which tag you use. You can find more information here. With that said, the way to change the name of a class or a property in Haxe is with the @native meta tag. Meta tags allow you to modify the behavior in the Haxe code. Each one has a specific use, but for now, we’re focusing on the current tag. Let’s look at an example below from my own code.

//In the output although the class is called ScenePause in Haxe, it will be LunaScenePause in the JS output.
class ScenePause extends Scene_MenuBase {
public var pauseTitleWindow: WindowTitle;
public var pauseMenuWindow: WindowPauseMenu;
public var pauseConfirmWindow: WindowConfirmMenu;
public override function create() {
view raw tags.hx hosted with ❤ by GitHub

As you can see above, all you need to do is add the tag above the property you want to change the name of; this could be a class, a property, or a function name. By using the native tag, we can make variations of the same function with type safety, avoid naming conflicts with other classes across the codebase (this was my use case). This is just the beginning.

There are several other tags you can use. If you notice above, there’s also the expose tag, which allows you to expose a class in the JavaScript output into the global namespace without writing a lot of the code yourself. This can be very helpful in certain instances.

Closing Remarks

There are a variety of tags you can use to help get something done in Haxe quickly and create something great! The ones I used today are compiler metadata flags. With that in mind, hope this helps you on your Haxe journey, and have a good one.

For more information on tags, you can find it here.

%d bloggers like this: