HaxeUI Tutorial

Connect Code to Widgets

John Gabriele

So far we’ve edited the assets/main.xml file and added numerous widgets, but they don’t connect to any of our Haxe code — they just look pretty. :)

To connect the widgets to code in Main.hx file, start with this simple main.xml file:

Notice we’ve added an id to the button. Now update your Main.hx file:

Instead of that button1.onClick assignment, if you wanted to add multiple handlers for one event, you could do:

The e argument passed to handleButton1 is a haxe.ui.events.UIEvent object. You can access the widget (a Component object) that generated the event via:

This is the way we’ll be accessing our widget objects going forward, and the examples in the following “more widget examples” sections will follow the same pattern as in the above example.