A newer version of Max is available. Click here to access the latest version of the Max documentation

The Maxobj Object

The Maxobj Object

A Maxobj is a Javascript representation of a Max object in a patcher. It is returned by various methods of a Javascript Patcher object, such as newobject().One important thing to keep in mind about a Maxobj is that it could eventually refer to an object that no longer exists if the underlying Max object is freed. The valid property can be used to test for this condition.

Maxobj Properties

rect [Array]

The location of an object in a patcher. When the object's rectangle is changed, it will move on screen if it is visible. The coordinates are stored in the following order: left, top, right, bottom.

maxclass [String]

The Max class (as opposed to the Javascript class, which is "Maxobj" and accessed via the standard class property) of the object.

patcher [object]

g/s(get)

The Patcher object that contains the Maxobj

hidden [Boolean]

Is the object set to be hidden in a locked patcher?

colorindex [Number]

If the object is set to use one of the standard 16 colors, this property is the index of the color

nextobject [object]

If there is another object after this one in the Patcher's list of objects, this property returns it, otherwise it returns a nil value

varname [String]

The patcher-specific name of the object, as set with the Name... dialog

canhilite [Boolean]

g/s(get)

Whether the object can be selected for text entry (a number box would be an example of an object whose canhilite property returns true)

background [Boolean]

Whether the object is in the Patcher's background layer

ignoreclick [Boolean]

Whether the object ignores clicks

selected [Boolean]

g/s(get)

Whether the object is selected in an unlocked patcher window.

js [object]

g/s(get)

If the Maxobj refers to an object is of Max class js, this returns the associated jsthis object

patchcords [object]

g/s(get)

Whether patchcords are connected to the object's inlets and outlets and, if so, the connected objects. Returns a generic object with two arrays, 'inputs' and 'outputs', of MaxobjConnection objects. These have the properties 'srcobject', 'dstobject', 'srcoutlet' and 'dstinlet' and can be used to walk the graph from JS.

valid [Boolean]

g/s(get)

Returns whether the Maxobj refers to a valid Max object

Maxobj Methods Overview

Perhaps the most powerful thing about a Maxobj is that you can send any message to a Maxobj that you can send to a Max object in Max as if you were invoking a method on the object in Javascript. For example, if you had a number box Maxobj and you wanted to set its value to 23 without outputting the value, you could do this:

n.set(23)

Note that certain words such as int, float, and delete are keywords in Javascript, and you will need to use either array notation or the message method for such reserved words. For example:

n.message("int", 23)
//or
n["int"](23)

The following methods are common to all Maxobj objects.

Maxobj Methods

message

Arguments

message [string]
anything [string]

Sends the object the message specified by the string, followed by any additional arguments provided. This is useful for sending messages to object which dynamically dispatch messages with the “anything” message, as is the case for instances of js, jsui, lcd, and others.

help

Opens a help file describing the object, if it exists

subpatcher

Arguments

index [number]

If the object contains a patcher, this function returns a (Javascript) Patcher object. The optional index is used for specifying an instance number, which only applies to poly~ objects. If the object does not contain a subpatcher, a nil value is returned.

understands

Arguments

message [string]

Returns a Boolean value if the object has an entry in its message list for the message specified by the string. If the entry is not a message that can be sent by a user within Max (i.e., it's a C-level “untyped” message), false is returned. This doesn’t work for messages which are dynamically dispatched with the “anything” message, as is the case for instances of js, jsui, lcd, and others.

getattrnames

Returns an Array value containing the names of available attributes for the object.

getattr

Arguments

attribute_name [string]

Returns the value of the attribute specified by attribute_name. Lists are returned as JS Array objects.

setattr

Arguments

attribute_name [string]
anything [string]

Sets the value of the attribute specified by attribute_name.

getboxattrnames

Returns an Array value containing the names of available attributes for the object's box.

getboxattr

Arguments

box_attribute_name [string]

Returns the value of the object's box attribute specified by box_attribute_name. Lists are returned as JS Array objects.

setboxattr

Arguments

box_attribute_name [string]
anything [string]

Sets the value of the object's box attribute specified by box_attribute_name.

See Also

Name Description
JavaScript Usage JavaScript Usage