Class: Resource

xebra.js v1.2.5 - Documentation

Resource

new Resource(0)

Represents some data that the remote Max instance has access to. The intended use is to support Max objects like fpic and live.tab, which may want to display images. Can also be used to fetch data from files in Max's search path. Setting filename (or setting dimensions in the case of .svg files) will query Max for that data in Max's search path. Listen for the Resource.event:data_received event to receive the data as a data URI string. Only images are currently supported.

Name Type Description
0 Xebra.NodeId optional

parentObjectId - The id of the ObjectNode that owns this resource

Example
// To use a resource without an ObjectNode, first create the resource.
const xebraState; // Instance of Xebra.State
const resource = xebraState.createResource();

// The resource doesn't hold on to data from Max once it receives it, so be sure to listen for Resource.event:data_received
// events in order to handle resource data.
resource.on("data_received", (filename, data_uri) => {
// Do something with the data
});

// Setting the filename property will cause the Resource object to fetch the data from Max. filename should be the
// name of a file in Max's search path. If Max is able to load the file successfully, it will send the data back
// to the Resource object, which will fire a Resource.event:data_received event with the data and filename.
resource.filename = "alex.png";

// If the requested file is an .svg file, then Max will render the file before sending the data back to the Resource
// object. In this case, the dimensions property of the resource must be set as well as filename.
resource.filename = "maxelement.svg";
resource.dimensions = {width: 100, height: 50};

Extends

  • EventEmitter

Members

Dimensions of the resource. These are not updated automatically, and cannot be used to determine the dimensions of a raster image in Max's filepath. Instead, use the data URI returned with the Resource.event:data_received event to determine size. Setting these dimensions will trigger a new data fetch, if the resource is an .svg image. Max will be used to render the image and a .png data-uri will be returned.

filename:string

Name of a file in Max's search path. Setting this will query Max for data from the corresponding file. Listen to the Resource.event:data_received event for the data in the form of a data-uri string.

id:Xebra.NodeId

readonly

Unique identifier associated with each resource.

isSVG:boolean

readonly

Whether the resource is a SVG image or not

objectContext:Xebra.NodeId

Id of the ObjectNode that owns the resource. If the resource is not bound to an ObjectNode, returns null. Max can use the object id to augment the search path with the parent patcher of the object, if the object id is supplied.

Methods

Be sure to call this when the Resource is no longer needed.

Events

Resource.event:data_received

Name Type Description
name string

name of the resource

datauri string

data-uri representation of the resource