Frame 1 var connected = false;
socket = new XMLSocket();
socket.ignoreWhite = true;
socket.onConnect = myOnConnect;
socket.onXML = myOnXML;
socket.onClose = myOnClose;
if (!socket.connect('class.mfaca.sva.edu', 4001)) {
    label.text = 'Failed to connect';
}

Here the port number is established as 4001 and a connection is opened to the server host that is running the BroadcastServer.

Functions defined in Frame 1 function myOnConnect(success) {
 if (success) {
    connected = true;
 } else {
    label.text = 'Failed to connect';
 }
}

function myOnXML(input) {
 var tag = input.firstChild;
 if (tag.nodeName == 'darker') {
    bulb._alpha -= 10;
    label.text = input.toString();
 } else if (tag.nodeName == 'lighter') {
    bulb._alpha += 10;
    label.text = input.toString();
 } else {
    label.text = tag.nodeName;
 }
}

function myOnClose() {
 connected = false;
 label.text = 'Closed';
}

function send(xmlStr) {
 var xml = new XML(xmlStr);
 if (connected) {
    label.text = 'sending ' + xml.toString();
    socket.send(xml + '\n');
 } else {
    label.text = "Can't send because we're disconnected";
 }
}

The send function is used below, within the individual botton scripts, to send XML to the BroadcastServer. The other functions are connected to the default events that are generated by the XMLSocket class (onXML, onConnect, onClose, etc.).

 

Disconnect button script on (press) {
    _root.send('<bye/>');
}
Lighter button script on (press) {
    _root.send('<lighter />');
}
Darker button script on (press) {
    _root.send('<darker />');
}