Removes the message listener.
The two parameters passed in to this function should match exactly the corresponding parameters passed into hwc.addMessageListener when the message listener was added.
<static> removeMessageListener( MessageListener, [containingObject] )
Name | Type | Argument | Description |
MessageListener | anonymous.MessageListener | The callback for message changes. | |
containingObject | Object | (optional) | If the containing object was given to hwc.addMessageListener when the message listener was added, then it also must be passed into this function. |
// 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 ); // If we want to remove the listener at some other point, use the following line of code: hwc.removeMessageListener( 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 "SI<4>" will trigger our callback function. var filter = new hwc.MessageFilter( null, "SI<4>", 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 ); // If we want to remove the listener at some other point, use the following line of code: hwc.removeMessageListener( messageListener, someObject );