show/hide named object

Peter Nyboer's icon

This seems so simple, but my simple brain doesn't want to grasp how to deal w/ maxobj properties. I just want to show or hide specific objects using javascript. I would have expected to do something like
this.patcher.objectname.hidden = 1
but that is too obvious, and wants to invoke a method, of course.

So how would I do this incredibly basic thing?

thanks,

Peter.

Wesley Smith's icon

JavascriptinMax.pdf p. 28. The hidden propert of a max object.

wes

Peter Nyboer's icon

i was there...

and my mail should have stated i also tried

this.patcher.objectname.hidden = 1

and that "objectname" is of course the "scripting name".
and variations on that. I'm totally lame w/ javascript. I've managed
to get some things done with it, quite happily, but i don't use it
enough for a "second nature."

so basically, i don't quite get it....

p.

Wesley Smith's icon

You have to do somthing like

myMaxObj = myPatcher.getnamed(objectName);
myMaxObj.hidden = 1;

It's a property of a JS maxobject. You can't reference it through
that crazy struct notation you posted.

wes

Peter Nyboer's icon

> You have to do somthing like
>
> myMaxObj = myPatcher.getnamed(objectName);
> myMaxObj.hidden = 1;
>
> It's a property of a JS maxobject. You can't reference it through
> that crazy struct notation you posted.

thanks for clearing that up. I told you I don't know what I'm doing!!

p.

Peter Nyboer's icon

and the resulting successful js and its associated helpfile

-------BEGIN JS----------

/*
    show and hide controls for input options
    takes a message "show ob n h" where
    ob is the "base" name of a group of objects, named ob[1], ob[2], and so on
     ( if you copy/paste a named object in Max, it results in names with the [n] appendage)
    n is the number of objects in the group
    h is the show/hide integer, where hide=1, show = 0.

by peter nyboer, with the help of the ever-knowledgeable Wes

*/    

//variables

var sinecontrols = 4;
var altname = "sine";

function show(ob,n,h)
{

    for (i=1;i
    altname = ob+"["+i+"]";
    intelement = this.patcher.getnamed(altname);
    intelement.hidden = h;
    }

}

---------------END JS----------------------

---------------BEGIN HELPFILE--------------

Max Patch
Copy patch and select New From Clipboard in Max.

---------------END HELPFILE--------------

Lasse Munk's icon

to me this made a little bit more sense:

Max Patch
Copy patch and select New From Clipboard in Max.

:)

not sure if the .js posts - if not:

inlets = 1;
outlets = 0;

var box = [8];
var paramName = "paramName";

function bang() {

for(var i = 0; i

paramName = String("paramName" + i);    

box[i] = this.patcher.newdefault(50*i,100,
                                "number", "@varname", paramName,
                                 "@fontsize", 10, "@minimum", 0, "@maximum", 127,
                                "@patching_rect",50*i,100,35, 30);

    }
}

function shit(h) {
var named = "shit";

for(i = 0; i

named = String("paramName" + i);

visible = this.patcher.getnamed(named);

visible.hidden = h;

}
    }