differentiate between textbutton toggle and button with js?

Sep 12, 2011 at 9:40pm

differentiate between textbutton toggle and button with js?

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

#58859
Sep 12, 2011 at 11:19pm

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");
    }
}
#211533
Sep 13, 2011 at 3:40pm

Ah, great, thank you! Is getattr documented somewhere? I was looking for something like that in the docs and found nothing.

#211534
Sep 13, 2011 at 10:34pm

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.

#211535

You must be logged in to reply to this topic.