Interact tag and SceenController does not work together


I followed the Nifty tutorials here on jME, but nothing happens when I try to get my ScreenController to do stuff using an interact tag.

I have the following XML:


<?xml version=“1.0” encoding=“UTF-8”?>

<nifty xmlns=“” xmlns:xsi=“” xsi:schemaLocation=“”>

<screen id=“start” controller=“game.user_interface.proxy$java.lang.Object$ScreenController$236c3ef8”>

<layer id=“layer1” backgroundColor="#00000000" childLayout=“center” width=“50” height=“50”>

<panel height=“10%” width=“20%” align=“center” valign=“center” backgroundColor="#f60f" childLayout=“center”>

<interact onClick=“sayHello()”/>

<text font=“Interface/Fonts/Default.fnt” text=“Hello World!” align=“center” valign=“center”/>






And the following ScreenController (in Clojure, but that shouldn’t be a problem):


(def controller (proxy [ScreenController] []

(bind [nifty screen] nil)

(onStartScreen [] nil)

(onEndScreen [] nil)

(sayHello [] (println “!!!”))))


The strange name of the controller in the XML is what I get when I do .getName on the controller class, so It should be correct.

I have everything form a recent nightly build of jME, including (these are jars I’m talking about): nifty-1.3, default-controls, and 2 styles.

I don’t get any error messages, and the text “Hello world!” shows up on the screen, so that works at least.

well the xml controller still looks pretty strange to me.

should be enough.

did u attach your screencontroller to the xml on startup? like
game.user_interface.Proxy proxy = new game.user_interface.Proxy();

nifty.fromXml(“Interface/helloworld.xml”, “start”, proxy);
well. dunno if those lines are accurate enough for clojoure but i think your custom controller isn’t (correctly) attached to nifty. would explain why u don’t get errors. to see if the controller is correctly attached just change your text from “hello world” to “hello it” oder something like that in the onStartScreen() method.

Yes, I did “fromXml”.

And onStartScreen works; I did a few printlns in onStartScreen and they show up.

I think there might be something wrong with the interact tag. If I change it to [xml]<interact onClick="sayHello"/>[/xml] then I get

[java]VARNING: Could not extract method from [sayHello][/java] when I click it. So at least it registers my clicks, but it does not correctly call the right method. How does that actually work?

first of all u need () @ onclick=“sayHello()”. they just say when the paramaters for the function start and stop. even if they are empty.

and since the onStartScreen method works the custom screencontroller is attached to nifty.

instead of

[xml]<interact onClick=“sayHello()”/>

<text font=“Interface/Fonts/Default.fnt” text=“Hello World!” align=“center” valign=“center”/>[/xml]


[xml]<control name=“button” id=“helloButton” label=“Hello” align=“center” width=“50%”>

<interact onClick=“sayHello()” />


i dunno if the problem lies with the clickable pannel but buttons should work.

if the control throws some errors try to paste

[xml]<useControls filename=“nifty-default-controls.xml” />[/xml]

between [xml]<nifty …>[/xml] and [xml]<screen …>[/xml]

Yes I know I it’s supposed to be onClick=“sayHello()”. I was just noting that when I leave out the parentheses I get an error message. So at least the interact tag is noticing clicks on it.

The useControls tag didn’t make any difference.

So my controller works (because onStartScreen works) and the interact tag registers clicks. There is, I guess, something wrong with the connection between the two. Possibly because I’m using Clojure. How does that whole connection work behind the scenes?


The problem was that proxy can not be used do define methods outside the interface.