XMLSocket.onXML()

Availability

Flash Player 5.

Usage

myXMLSocket.onXML(object) = function() {
  // your statements here
}

Parameter

object An XML object that contains a parsed XML document received from a server.

Returns

Nothing.

Description

Event handler; invoked by Flash Player when the specified XML object containing an XML document arrives over an open XMLSocket connection. An XMLSocket connection may be used to transfer an unlimited number of XML documents between the client and the server. Each document is terminated with a 0 (zero) byte. When Flash Player receives the 0 byte, it parses all of the XML received since the previous 0 byte, or since the connection was established if this is the first message received. Each batch of parsed XML is treated as a single XML document and passed to the onXML method.

The default implementation of this method performs no actions. To override the default implementation, you must assign a function containing actions that you define.

Example

The following function overrides the default implementation of the onXML method in a simple chat application. The function myOnXML instructs the chat application to recognize a single XML element, MESSAGE, in the following format.

<MESSAGE USER="John" TEXT="Hello, my name is John!" />. 

The onXML handler must first be installed in the XMLSocket object as follows:

socket.onXML = myOnXML;

The function displayMessage() is assumed to be a user-defined function that displays the message received by the user.

function myOnXML(doc) {
  var e = doc.firstChild;
  if (e != null && e.nodeName == "MESSAGE") {
    displayMessage(e.attributes.user, e.attributes.text);
  }
}

See also

function