-
Hi all, I am pretty new to ClearScript and could use some advice from the community. In my case, I have a C# event that I would like to be able to subscribe and unsubscribe to from JS. In this case specifically, it has to do with a GUI. So I will use a Button object as the example. Context: element is the btn object itself and is always supplied as an argument when onPressed is triggered. let btn = new Button();
// 3 possibilities
// 1
btn.onPressed = (element) => {/*logic here*/};
//2
btn.onPressed = function (element) {/*logic here*/};
// 3
function whenPressed(element) {
/* logic here */
}
btn.onPressed = whenPressed; Honestly, I am just not sure what to do on the C# side... I got it somewhat working by creating a method in my C# class public void addOnPressedHandler(string scriptName, string func)
{
this.onPressed = element => {
var engine = // get the engine from the name of the script
engine.Trigger(func, element);
}
} and I could call it from JS like this function onButtonPressed(element) {
/* logic here */
}
btn.addOnPressedHandler('nameofscript', 'onButtonPressed'); The downside of this, though, is that I would always have to know the name of the script and pass it in. I think I could bear with this implementation if I was able to implicitly provide the value of the script, but I do not think that is possible as far as I know. If possible, I would greatly prefer the first implementation, but I could get by with the second if I did not have to provide the name of the script. Perhaps my whole approach is incorrect, in which case I would like to be corrected. I would be glad to provide more context if needed. Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I ultimately found the answer at #240. I just did not know what I was looking for. My question has been answered. |
Beta Was this translation helpful? Give feedback.
I ultimately found the answer at #240. I just did not know what I was looking for. My question has been answered.