Closed patrixd closed 8 years ago
Hi,
Any chance you can share a project / source? What you describe should be fine.
Cheers, Ian
this seems to work fine for me: https://dl.dropboxusercontent.com/u/26678671/CustomTest.zip
Ok, I know what is the problem. I want to reference the custom component from the controller to modify it. If I change your code and add an id to customcontroller and in the controller I use the id as variable I get the warning and errors that I told you. The compailer says testComponent is an unknown identifier. How can I use my Custom Component from the Controller? Like your button testButton but as a custom component. How would you use it? In my case I need a custom button with many states, and when the controller changes the state, the component itself changes the source. main.xml
<vbox id="main">
<button id="testButton" text="Click Me!" />
<customcomponent id="testComponent" />
</vbox>
mainController.hx
public function new() {
testButton.onClick = function(e:UIEvent) {
testButton.text = "Thanks!";
};
if (testComponent != null) {
testButton.text = "Works!";
}
}
Hmmm... you are right, once you give it an id i get the warning also, looks like a bug. Leave it with me and ill see if i can work out whats happening.
Cheers, Ian
Ok, i can see what the issue is. So, the build macro for the controller is run at compile time and creates the member variables, however, the call to ClassManager.instance.registerComponentClass
only happens at runtime, ie, when the application starts. This means that when you assign an id to the custom component in the XML the macro can find the associated class. The fix is pretty simple: use a module.
Basically, create a file called module.xml
and put the following it in:
<?xml version="1.0" encoding="utf-8" ?>
<module>
<exports>
<component class="haxe.ui.custom.test.CustomComponent" />
</exports>
</module>
This then registers the class at compile time, if you are registering a single class you can also use the "alias" attribute to let haxeui know what you would like to use in the xml (if you omit the attribute then the lower case class name is used).
Finally, if you have more than one custom component it might make sense to use "package" instead of "class" in the <component>
node. HaxeUI is a module itself and exports its classes using this module.xml: https://github.com/ianharrigan/haxeui/blob/master/haxe/ui/toolkit/module.xml
Hope that helps!
Cheers, Ian
Thank you so much. How and where do I must to assign module.xml. I can't find it.
Just create a file called module.xml
in your application somewhere on the class path, HaxeUI will automatically find it.
Let me know if that works and this can be closed?
It works! It can be closed. Maybe the wiki must be updated. Thank you so much :+1:
Great! Glad its working! :+1:
Hi I have followed the steps defined in the wiki to register a custom component and use it in the XML template. https://github.com/ianharrigan/haxeui/wiki/Custom-Components
But I allways get the next warning: Macros.hx:479: WARNING 'customcomponent' hasnt been defined And if I use the custom component there are undefined errors in my haxe views classes that build the xml controller that has the custom component. The warning only appears when I add the customcomponent to a xml. Its like ClassManager.instance.registerComponentClass(CustomComponent, "customcomponent"); before Toolkit.init() in Main does not work.
If I change the customcomponent for an Image (as example the variables are defined and there is not Macros warning) in the xml it works.
Why doesn't customcomponent work?