differentiate between textbutton toggle and button with js?


    Sep 12 2011 | 9:40 pm
    Is it possible to get the mode of a textbutton in javascript? Working from the "patchdescribe.js" in the example, we can find all the textbuttons in a patch, but is it possible to parse out the toggles vs. the momentaries? I've tried this, however, "b.mode" doesn't really give me something I can use. It's a jsobject, and it's not really clear how to extract the actual value of the mode so I know if it is a toggle or not.:
    function bang()
    {
    this.patcher.apply(iterfun);
    }
    function iterfun(b)
    {
    //post("nclass",b.maxclass);
    if(b.maxclass=="textbutton"){
    post("n----");
    for(i in b){
    post("nb",i,b[i]);
    }
    if(b.mode){
    post("ntog",b.mode);
    }else{
    post("nmom",b.mode);
    }
    }
    return true;
    }
    iterfun.local=1; // keep private

    • Sep 12 2011 | 11:19 pm
      Try using the getattr() method, here's a quick example:
      var modes = ["button","toggle"];
      
      function bang() {
          this.patcher.apply(iterbutton);
      }
      
      function iterbutton(a) {
          if(a.maxclass == "textbutton") {
              post(modes[a.getattr("mode")],"n");
          }
      }
    • Sep 13 2011 | 3:40 pm
      Ah, great, thank you! Is getattr documented somewhere? I was looking for something like that in the docs and found nothing.
    • Sep 13 2011 | 10:34 pm
      I'm not entirely sure it is, maybe somewhere in the PDF documentation that came with Max4, either that or I learned about it somewhere here on the forum. It does have a few caveats, but if you're working mainly with UI objects you shouldn't really get stuck.