Issues with module generating classes

So in the docs about modules it says that we can create component classes with plain markup.

this is the markup I have:

<?xml version="1.0" encoding="utf-8"?>
<hbox>
    <textfield id="hello" text="Hello World !">
    </textfield>
</hbox>

this is the module def:

<?xml version="1.0" encoding="utf-8"?>
<module id="test">
    <components>
        <class file="../Assets/custom/test1.xml" alias="CustomAlias" >
        </class>
	<class folder="../Assets/custom" >
        </class>
    </components>
</module>

But in the ModuleMacros class when I trace the class componentEntries of my test module trace([c.className,c.classFolder,c.classAlias]); after line 185 I get this output:

/ModuleMacros.hx:186: [null,null,CustomAlias]

/ModuleMacros.hx:186: [null,../Assets/custom,null]

So essentially the test1.xml is not created as a class because it doesn’t have either a className or a classPackage(classPackage is null also) and to create a valid var types we need to have to have non null classPackage and className.

Is this normal behaviour ? Am I missing something ?

The initial issue is that I can’t get the class from haxe code i.e. var t = custom.Test1(); gets me compilation errors saying Type not found.

Any chance you can attach your project?

Cheers,
Ian

Here it is; It is a Kha project and I use the most recent version of Kha with Haxe rc3(but it probably overrides my settings in vscode).

does var t = assets.custom.Test1(); work?

No got the same compilation error with Type not Found. I also tried haxe.ui.assets.custom.Test1 and still no cigar.

When i try and run you app i keep getting ReferenceError: require is not defined, which is strange as its client side and kha seems to be looking for electron (var electron = untyped __js__("require('electron')");), am i missing something?

Cheers,
Ian

OK, nevermind, figured it out… kha_debug_html5 was a define, and that got it to that block… without it, it seems to run fine:

image

Though im not sure if this has the custom component there or commented out.

Ill check

Cheers,
Ian

OK, well, i can see the problem… its trying to create a class ...Assets.custom.CustomAlias rather than assets.custom.CustomAlias… will fix that now.

Ok, that should be fixed in master now, i also noticed a number of issues regarding textfields in kha so fixed them while i was there. You’ll need latest master of haxeui-core and haxeui-kha. Also, while poking around your app i noticed your login form with, what looked to be, a custom placeholder. You can of course go down that route and do it all yourself, but just in case you didnt know, textfields in haxeui already have a placeholder property:

<textfield placeholder="Username" style="font-size: 24px;" />
<textfield placeholder="Password" password="true" style="font-size: 24px;" />

image

Hope that helps, and let me know if the original issue is gone (it should be).

Cheers,
Ian

1 Like

The issue is solved yes.

Thanks for the support and the info ! For the placeholder it’s good to know… I went through the source but sometimes when it’s not clear I just try to do it myself but will use the placeholder now :slight_smile:

To anyone looking at the post to get the class you need to give the whole path to the file. Since mine is in the Kha Assets folder i.e. Assets/custom/test1.xml I need to write to be able to create the class assets.custom.Test1. An issue pertaining to writing the code is that the language server doesn’t seem to find the class even though it is created with a macro. Will report this to the language server team;