Problem creating new patcher with JS

Nov 29, 2008 at 5:09pm

Problem creating new patcher with JS

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

#41104
Nov 30, 2008 at 1:57am

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??

#146053
Dec 2, 2008 at 2:52am

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

#146054
Oct 7, 2013 at 11:28am

Use patcher.front() to see the window.

Cheers

-A

#267352

You must be logged in to reply to this topic.