static outlet method ?

Jul 20, 2008 at 2:39pm

static outlet method ?

Hello,

I’m trying to use outlet() in a static method. the compilator tells me :

on-static method outlet(int,int) cannot be referenced from a static
context

This is strange because the post() method works fine.
Does anybody knows how I can do ?

many thanks !!!!

O..////

#38952
Jul 20, 2008 at 2:57pm

Olivier –

I think if you associate the non-static method explicitly with an object
you can call it from the static context (i.e. the dynamic object has to
exist or be referenced). This may work:

MaxObject.outlet();

or you may have to do this:

MaxObject MyMaxObject = new MaxObject();
MyMaxObject.outelt();

but I’m not sure how well they will function in an mxj object context
(the
outlet method then called may not be associated properly with the
mxj object you are building). And I may be wrong…

brad

http://music.columbia.edu/~brad

On Jul 20, 2008, at 10:39 AM, olivier pasquet wrote:

> Hello,
>
> I’m trying to use outlet() in a static method. the compilator tells
> me :
>
> on-static method outlet(int,int) cannot be referenced from a static
> context
>
> This is strange because the post() method works fine.
> Does anybody knows how I can do ?
>
> many thanks !!!!
>
> O..////

#136375
Jul 20, 2008 at 3:37pm

I don’t think outlet() can be expected to work in a static method.

post() works because there’s only one Max window. You may have many instances of your mxj object and therefore many outlets that could be the target.

What are you trying to do?

Do you want the int to be sent from the outlet of only one of your instances or ALL of them? (The latter of these might warrant the use of a static method, e.g., you could keep track of all of your instances and use a static method to send a message out of all of your objects’ right outlets.)

#136376
Jul 20, 2008 at 10:47pm

Hi,

olivier pasquet wrote:
> This is strange because the post() method works fine.
> Does anybody knows how I can do ?

This is not strange at all. If you read the javadoc for MaxObject,
you’ll see that post is declared as

static void post ( java.lang.String message )

On the other hand, every outlet method is declared as non-static. Since
you can’t call instance methods from a static method (how would that be
possible anyway?), but you can call other static methods, this behavior
is quite ordinary.

Cheers,
Adam

#136377
Jul 21, 2008 at 10:16am

Hi Adam,

Thanks for your response!!

> but you can call other static methods, this behavior is quite
ordinary.
< How then can I do if I want outlet() behave as a static method ?

Why post() is static and not outlet() ?

#136378
Jul 21, 2008 at 10:31am

Quote: Olivier Pasquet wrote on Mon, 21 July 2008 11:16
—————————————————-
>
> Why post() is static and not outlet() ?
>
—————————————————-

Because post() prints messages in the Max window and there is only one Max window.

#136379

You must be logged in to reply to this topic.