Theres a few different ways, depending on how you are using haxeui. The way you are using it above your only real option is:
var button = main.findComponent("button1", Button);
button.onClick = function(e) { ... };
button.registerEvent(MouseEvent.CLICK, function(e) { ... });
However, if you were using custom components and build macros things get much better:
@:build(haxe.ui.macros.ComponentMacros.build("assets/main.xml"))
class MainView extends Component {
@:bind(button1, MouseEvent.CLICK)
function onButton1(e) {
button2.text = "clicked"; // note: all named components are now correctly typed member vars
}
}
using this class in Main.hx you just remove the var main:Component = ComponentMacros.buildComponent("assets/main.xml"); and replace with var main = new MainView();
Hope that helps
Cheers,
Ian