Currently there isnt a method exactly as you describe, in the sense that you define your click handler in XML and that links to haxe code - there is this open issue which is essentially as you describe: https://github.com/haxeui/haxeui-core/issues/196 - and I think it would a useful addition.
There is however this method (using build macros to build a custom component):
@:build(haxe.ui.macros.ComponentMacros.build("myxml.xml"))
class MySomething extends Box {
public function new() {
super();
myButton.onClick = function(e) {
myLabel.text = "Clicked";
}
}
}
This macro takes your xml (see below) and creates correctly typed member variables of anything that has an id.
<vbox>
<button id="myButton" />
<label id="myLabel" />
</vbox>
This can then be used in code or xml freely:
Screen.instance.addComponent(new MySomething());
Screen.instance.addComponent(new MySomething());
Screen.instance.addComponent(new MySomething());
or
<vbox>
<mysomething />
<mysomething />
<mysomething />
</vbox>