Addressing TextButton Label Text via Javascript?


    Nov 21 2012 | 5:46 pm
    I'm trying to change many textbuttons' text with a simple javascript, but I can't figure out how to address the button's text. Is this possible or do I have to use a JSUI object to make the buttons first.
    I'm attaching a small example.
    Thanks!

    • Nov 21 2012 | 6:19 pm
      Hi Whale Bone,
      One way of doing it is to just send a message to the object, using 'myobject.message()':
      inlets = 1;
      outlets = 1;
      autowatch = 1;
      p = this.patcher;
      var textvalues = ["Off","On"];
      function ToggleButton(a) {
      if (a==0) { Setting=0; } else { Setting=1; }
      var b=p.getnamed("buttonOnOff");
      b.message("text", textvalues[a]);
      }
    • Nov 21 2012 | 7:50 pm
      Thanks so much! I had tried that, but I realize now that I'd forgotten to include the "text" argument. D'oh! So simple.
      Thanks again.
    • Nov 21 2012 | 7:55 pm
      Alternately, you can set the attr like this:
      b.text(textvalues[a]);
      -Ben
    • Nov 22 2012 | 3:59 am
      Thanks again. That's very helpful.