Forums > MaxMSP

Problem creating new patcher with JS

November 29, 2008 | 5:09 pm

Having trouble creating a new patcher window with Javascript. Using this code:

function newpatch(){
p = new Patcher(50,50,200,200);
p.wind.visible=true;
}

No errors reported in the Max window… What am I doing wrong?

Thanks,
Brennon


November 30, 2008 | 1:57 am

Wow…this shouldn’t be this hard…

To create a new patcher, quoting from the documentation:

var p = new Patcher(left,top,bottom,right);

And further down in the documentation, under Patcher object properties:

wind (Wind, get)
A Javascript representation of the window associated with the patcher.

So, I’ve also tried setting some of those properties. Here’s what I’m working with now:

var myPatcher = new Patcher(100,100,400,400);

function bang(){
myPatcher.dirty();
myPatcher.wind.visible = 1;
myPatcher.wind.bringtofront();
myPatcher.newdefault(10,10,"toggle");
post("myPatcher.parentclass:");
post(myPatcher.parentclass);
post("n");
post("myPatcher.wind.visible:");
post(myPatcher.wind.visible);
post("n");
post("myPatcher.wind.location:");
post(myPatcher.wind.location);
myPatcher.wind.location = (0,0,100,100);
post("myPatcher.wind.location:");
post(myPatcher.wind.location);
post("n");
post("myPatcher.wind.assocclass:");
post(myPatcher.wind.assoclass);
post("n");
post("myPatcher.wind.assoc:");
post(myPatcher.wind.assoc);
post("n");
myPatcher.bringtofront();
myPatcher.fullscreen(1);
myPatcher.apply(printOut);
}

function printOut(){
post("I found a Maxobj!");
}

I’ve included all of my debugging code, as well. Here is my typical output:

js: myPatcher.parentclass: jsobject 0
js: myPatcher.wind.visible: 0
js: myPatcher.wind.location: 100 100 400 426
method getwind called on invalid object
js: myPatcher.wind.location: 100 100 400 426
js: myPatcher.wind.assocclass:
js: myPatcher.wind.assoc: jsobject 37535792
js: I found a Maxobj!

—–

If I comment out the line,

myPatcher.newdefault(10,10,"toggle");

I do NOT get the debugging output:

js: I found a Maxobj!

So, I know the patcher and toggle are being created, I just can’t see them or manipulate them. Is this a bug?

For what it’s worth, I CAN create a subpatcher with the following Javascript:

var p=this.patcher;
var subp = p.newdefault(100,100, "p", "patcherName");

function hide(){
subp.wind.visible = 0;
}

function show(){
subp.wind.visible = 1;
}

But when I call the hide or show functions, I get:

js: old_gimme.js: Javascript TypeError: subp.wind has no properties, line 4
js: error calling function hide
js: old_gimme.js: Javascript TypeError: subp.wind has no properties, line 8
js: error calling function show

I’m pulling my hair out here…does ANYONE have an idea??


December 2, 2008 | 2:52 am

Can this message be moved to the JS forum, please?


October 7, 2013 | 11:28 am

Use patcher.front() to see the window.

Cheers

-A


April 25, 2014 | 12:10 am

I have the same problem, I tried patcher.front(); and it does not work. Anyone please have any idea about how to
create a new patcher using javascript? Thank you


April 25, 2014 | 12:22 am

Hi, I tried this and the patcher was created. It seems that the variable should be declared inside the function.

autowatch = 1;

function bang(){
var myPatcher = new Patcher(100,100,400,400);

myPatcher.wind.visible = 1;
myPatcher.wind.bringtofront();
myPatcher.newdefault(10,10, "toggle");
myPatcher.bringtofront();
myPatcher.fullscreen(1);
myPatcher.front();
}


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