addMessageListener( filters, MessageListener, [containingObject] ) method

Registers a message listener.

Syntax

<static> addMessageListener( filters, MessageListener, [containingObject] )

Parameters

Name Type Argument Description
filters hwc.MessageFilter   The message filter that message events must pass to get passed to the anonymous.MessageListener. If no filter is desired, then null can be used for this parameter.
MessageListener anonymous.MessageListener   The callback function for message changes.
containingObject Object (optional) The containing object of the message listener.If a message listener callback function references variables in its containing object, then the containing object should be passed to this function.

Example

// soSomething is a global function called by the listener callback.
var doSomething = function()
{
   alert("New message!");
}
// messageListener is the callback function passed to hwc.addMessageListener.
var messageListener = function( flag, messageId )
{
   if( flag == hwc.MSG_ADDED )
   {
      doSomething();
   }
}
// We do not want to filter the message events the listener will get invoked for, so pass null for the first parameter.
hwc.addMessageListener( null, messageListener );
// someObject is an object that will contain the listener callback as well as a variable referenced by the callback.
var someObject = {};
// doSomething is a function referenced by the callback function.
someObject.doSomething = function()
{
   alert("New message!");
}
// messageListener is the callback that will be passed to hwc.addMessageListener.
someObject.messageListener = function( flag, messageId )
{
   if( flag == hwc.MSG_ADDED )
   {
      this.doSomething();
   }
}
// Create a filter so that not all message events will invoke our callback function.
// Only events about messages with a subject of "Subject" will trigger our callback function.
var filter = new hwc.MessageFilter( null, "Subject", null, null, null, null);
// The callback function references a variable in its containing object, so we need to pass in the containing object
// in addition to the filter and the callback function.
hwc.addMessageListener( filter, someObject.messageListener, someObject );

Source

hwc-api.js, line 2782.