XML Feeds

.

[java-dev] Bug/limitation: outlet() does not work in the constructor

Adam Murray adamjmurray at gmail.com
Thu Sep 6 19:22:43 MDT 2007


As demonstrated in the included external and patch, any calls to outlet() inside the constructor seem to be ignored.

Here is my problem. I have a custom attribute getter/setter, similar to the example external, and I really need the value to be sent out ANYTIME the attribute is set, which includes not only via max messages (that works fine), but also when using attributes to construct the object (mxj AttributeTest @myattr 2). The latter case does not work because of the limitation with outlet() in the constructor.

Any suggestions for how I can send out the attribute values in this situation? I thought I might be able to use the loadbang() method, but the APIs say "Note that you do not get the loadbang message when the user creates a new instance of your object in the Patcher window, only when a Max file containing your class is loaded from disk." I also need it to work when a new instance is created.

Adam

Java external:
[code]
import com.cycling74.max.Atom;
import com.cycling74.max.MaxObject;

public class AttributeTest extends MaxObject {

	private int myattr = 0;

	public AttributeTest(Atom[] args) {
		declareIO(1, 1);
		declareAttribute("myattr", "getmyattr", "myattr");
		outlet(0, "finished the constructor"); // doesn't do anything
	}

	public int getmyattr() {
		return myattr;
	}

	public void myattr(int myattr) {
		post("In myattr()"); 
		this.myattr = myattr;
		outlet(0, myattr); // only works when receiving myattr messages via the inlet
	}
}
[/code]

**********
Max patch:

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 49 51 51 196617 myattr 1;
#P newex 49 102 81 196617 print mxjoutput;
#P newex 49 77 145 196617 mxj AttributeTest @myattr 2;
#P connect 0 0 1 0;
#P connect 2 0 0 0;
#P window clipboard copycount 3;




More information about the java-dev mailing list