how to react to clicks on a dynamically created button with JS
I could use some help with the following situation:
What I tried/what I am looking for is something in the lines of:
myButton = this.patcher.newdefault(buttonXPosition, buttonYPosition, "live.text", "aName");
myButton.onclick = someFunction();
Thank you so much for your help! I appreciate it.
I searched the attributes of live.text and button but there does not seem to be an attribute like "clicked". I would do it like you describe it in your workaround.
Concerning the slow down of the patch: did you think about creating these message IDs before runtime?
Thanks for your quick reply! Yes, I am creating the message IDs before runtime. Unfortunately, my interface is dynamic/changing according to the choices of the user during the performance… so there will be new buttons (and hence messages) created almost constantly… I will explore this further :D Thanks again!
if anyone knows of any other way, I’d also like to hear…
thanks – I’ll let you know in case I find another way…. ! cheers :)
Just wanted to let you know that I made my own jsui buttons to gain access to the on click function. Cheers, Hanna
Nice idea. Do you have an example?
An example? Well, I used the example buttons in the jsui-helpfile as a starting point/example. I modified one of the example buttons a bit and called the jsui button "myjsbutton.js". Then I can dynamically create the jsui-buttons like this with JS (makemyinterface.js):
myButtons[count] = this.patcher.parentpatcher.newdefault(tagXPosition, tagYPosition, "jsui", "tag");
myButtons[count].varname = "tag"+count;
In the myjsbutton.js file, I used this code to report the clicks to a [r receiver] object (make sure to give it the scripting name "receiver").
I connect the [r receiver] object to the makemyinterface.js file.
I am not sure if this is the best way to do this, but it is at least one way to do it. The only disadvantage I found is that one can not scroll the patch when the mouse is over a jsui object…..