Forums > Javascript

global Maxobj properties?

January 10, 2007 | 11:44 pm

This is my first attempt at working with Javascript so please forgive my naivete. I have a very simple function that queries the class, name, and coordinates of named objects in a patch. I want to use it in a nested subpatch below the objects I’d like to query. I’d really like to perform the function globally but I’m stuck on the steps involved. I’ve tried to work up in the subpatch chain using the box property and then down again, but it doesn’t seem to work as needed. Is there something more efficient I’m overlooking? Here is the idea before going up or down in the hierarchy…

Joe Branciforte
____________________________________________________________

autowatch= 1
outlets= 1;
inlets=1 ;

function names(){

var obj = this.patcher.firstobject;

while(obj) {
if (obj.varname !="") {
outlet(0, obj.maxclass, obj.varname, obj.rect);
obj = obj.nextobject;}
else {obj = obj.nextobject;}
}
}


January 11, 2007 | 2:27 pm

I think this is what you’re looking for:

autowatch= 1
outlets= 1;
inlets=1 ;

function names()
{
namesRecursive(top(), 0);
}

function namesRecursive(p, level)
{
if (p)
{
printNames(p);
var obj = p.firstobject;
while(obj)
{
if (obj.maxclass = "patcher") namesRecursive(obj.subpatcher(), level+1);
obj = obj.nextobject;
}
}
else return
}

function printNames(p)
{
var obj = p.firstobject;
while(obj)
{
if (obj.varname !="") outlet(0, obj.maxclass, obj.varname, obj.rect);
obj = obj.nextobject;
}
}

function top()
{
var prev = 0;
var owner = this.patcher;
while (owner)
{
prev = owner;
owner = owner.parentpatcher;
}
return prev;
}

Mattijs


Viewing 2 posts - 1 through 2 (of 2 total)