The MaxobjListener Object

The MaxobjListener object listens for changes to a Maxobj object's value, or changes to a specified attribute of a Maxobj object. When a change occurs, a user-specified function will be called. The object also provides methods for getting and setting the value of the observed value or attribute.

MaxobjListener Constructor

var ml = new MaxobjListener(object, [attribute_name], function);

The object argument is a Maxobj. If the attribute_name argument is specified, the MaxobjListener object will observe that named attribute. Otherwise the object's value will be observed. Note that not every Max object has an observable value -- objects compatible with the pattr family of Max objects can be observed in this fashion. Practically, that means nearly every UI object as well as a handful of normal Max box objects (including js, pattr and dict). Attributes can be observed for any Maxobj which has attributes.

The function argument specifies the function you want to execute. The function should have a single argument, which is a MaxobjListenerData object.

Example:

function valuechanged(data) {
  post("value changed!\n")
  if (data.attrname) {
    post("attrname: " + data.attrname + "\n")
  }
  post("new value: " + data.value + "\n")
}

ob = this.patcher.getnamed("someobject")
l = new MaxobjListener(ob, "patching_rect", valuechanged)

For convenience, the MaxobjListener object is a property of the MaxobjListenerData argument to the function. To access the MaxobjListener from within its function:

data.listener

MaxobjListener Properties

maxobject [Maxobj]

The Maxobj to observe.

attrname [string]

An attribute to observe for changes, if desired.

MaxobjListener Methods

getvalue

Report the value of the Maxobj or its specified attribute. List values are reported in a JS Array object.

setvalue

Set the value of the Maxobj or its specified attribute.

MaxobjListenerData

The MaxobjListenerData object is the argument to your MaxobjListener's function

MaxobjListenerData Properties

listener [MaxobjListener]

g/s(get)

The MaxobjListener which called the function.

maxobject [Maxobj]

g/s(get)

The Maxobj being observed.

attrname [string]

g/s(get)

If the MaxobjListener is observing an attribute, the attribute's name, otherwise undefined.

value [value or Array]

g/s(get)

The current value of the observed object or attribute. List values are represented by a JS Array object.

See Also

Name Description
JavaScript Usage JavaScript Usage