list in maxObjListener

GllmS.'s icon

Hello !
I have a [js] object that listen to 4 numbox that each represent a color (RGBA). I'm just looking for a more elegant way of doing this. Instead of sending the values separatly, I want to send a single list of 4 values in the callbackColor function. I can't figured how to do that ?

function init(){
    var alpha = this.patcher.getnamed("alpha");
    alpha.set(255);
    alpha.listener = new MaxobjListener(alpha, callbackColor);
 
    var red = this.patcher.getnamed("red");
    red.set(255);
    red.listener = new MaxobjListener(red, callbackColor);
 
    var green = this.patcher.getnamed("green");
    green.set(255);
    green.listener = new MaxobjListener(green, callbackColor);
 
    var blue = this.patcher.getnamed("blue");
    blue.set(255);
    blue.listener = new MaxobjListener(blue, callbackColor);
}
function callbackColor(data){
    outlet(0, "/" + trackName + "/color" + , data.value );
}
GllmS.'s icon

In case someone is looking for an answer, I just listen to a [swatch] object that return a list.

tyler mazaika's icon

If you wanted the independent numboxes, just call getvalue on each of the MaxobjListener objects:

function callback(){
 return [ red.getvalue(), green.getvalue(), blue.getvalue(), alpha.getvalue() ]
}
GllmS.'s icon

thank's tyler !
It's working, but I had to call getvalue this way because of how I declare it.
red.listener.getvalue() etc...