// ********************************************************************************
// utility actionscript: spacebox client interaction
// mathias ochsendorf : ochsendorf@hbt.arch.ethz.ch
// october 2004
// ********************************************************************************
// public methods
// ---------------
//
// set the level of individual elements (lights/window):
// ********************************************************************************
function NR1(theValue){
trace("set level of NR1 to:" + theValue);
sockOsgi.send("NR1setLevel"+ theValue + "");
}
function NR2(theValue){
trace("set level of NR2 to:" + theValue);
sockOsgi.send("NR2setLevel"+ theValue + "");
}
function NR3(theValue){
trace("set level of NR3 to:" + theValue);
sockOsgi.send("NR3setLevel"+ theValue + "");
}
function NR4(theValue){
trace("set level of NR4 to" + theValue);
sockOsgi.send("NR4setLevel"+ theValue + "");
}
function NR5(theValue){
trace("set level of NR5 to:" + theValue);
sockOsgi.send("NR5setLevel"+ theValue + "");
}
function LS1(theValue){
trace("set level of LS1 to:" + theValue);
sockOsgi.send("LS1setLevel"+ theValue + "");
}
function LS2(theValue){
trace("set level of LS2 to:" + theValue);
sockOsgi.send("LS2setLevel"+ theValue + "");
}
function LS3(theValue){
trace("set level of LS3 to:" + theValue);
sockOsgi.send("LS3setLevel"+ theValue + "");
}
function LS4(theValue){
trace("set level of LS4 to:" + theValue);
sockOsgi.send("LS4setLevel"+ theValue + "");
}
function LS5(theValue){
trace("set level of LS5 to:" + theValue);
sockOsgi.send("LS5setLevel"+ theValue + "");
}
function LS6(theValue){
trace("set level of LS6 to:" + theValue);
sockOsgi.send("LS6setLevel"+ theValue + "");
}
function LS7(theValue){
trace("set level of LS7 to:" + theValue);
sockOsgi.send("LS7setLevel"+ theValue + "");
}
function LS8(theValue){
trace("set level of LS8 to:" + theValue);
sockOsgi.send("LS8setLevel"+ theValue + "");
}
function LS9(theValue){
trace("set level of LS9 to:" + theValue);
sockOsgi.send("LS9setLevel"+ theValue + "");
}
function LS10(theValue){
trace("set level of LS10 to:" + theValue);
sockOsgi.send("LS10setLevel"+ theValue + "");
}
function WINDOW(theValue){
trace("set level of WINDOW to:" + theValue);
sockOsgi.send("WINDOWsetLevel"+ theValue + "");
}
function switchAll(theValue){
trace("set level of all devices to:" + theValue);
sockOsgi.send("NR1setLevel"+ theValue + "NR2setLevel"+ theValue + "NR3setLevel"+ theValue + "NR4setLevel"+ theValue + "NR5setLevel"+ theValue + "LS1setLevel"+ theValue + "LS2setLevel"+ theValue + "LS3setLevel"+ theValue + "LS4setLevel"+ theValue + "LS5setLevel"+ theValue + "LS6setLevel"+ theValue + "LS7setLevel"+ theValue + "LS8setLevel"+ theValue + "LS9setLevel"+ theValue + "LS10setLevel"+ theValue + "");
}
// react on server responses containing status change information
// ********************************************************************************
function processResponse(node){
if(node.nodeName == osgiPrefix + "message" || node.nodeName == osgiPrefix + "rcbox" )
{
traverse_XML_message(node);
trace("processResponse value of " + myNodeID + " changed to: " + myNodeValue);
//===
// do something with that information
//===
//if(myNodeID==0){
// gotoAndStop(1);
//}
//else if(myNodeID=="NR1"){
// gotoAndPlay(4);
//}
//else if(myNodeID=="NR2"){
// gotoAndStop(3);
//}
//else {
// gotoAndStop(1);
//}
return;
}
if(!node.hasChildNodes()) return;
var n = node.firstChild;
do{processResponse(n);} while(n = n.nextSibling);
}
// global variables and socket connections
// ********************************************************************************
if (!_global.initialize)
{
trace("template is loaded");
_global.initialize = true;
_global.osgiServer = "styropor.ethz.ch";
_global.osgiPort = 4445;
_global.osgiPrefix = "";
sockOsgi = new XMLSocket();
sockOsgi.onXML = onSockMessage;
sockOsgi.onConnect = onSockConnectOsgi;
sockOsgi.onClose = onSockCloseOsgi;
sockOsgi.returnField = "\n ";
sockOsgi.connect(osgiServer, osgiPort);
}
// background functionality
// ********************************************************************************
// a message from the server received
function onSockMessage(xml_response) {
processResponse(xml_response);
}
// connect to the server
function onSockConnectOsgi(success)
{
if (success)
{
trace ("connected to osgi server ");
} else {
trace ("connection to osgi server failed");
}
}
// disconnection from the server
function onSockCloseOsgi() {
trace ("lost connection to osgi server");
}
// send a message to the server
// @param array with the element ids
// @param the invoked method
// @param the value
function sendSockXML(myIDs, myMethod, myValue) {
message = new XML();
message_spacebox = message.createElement("spacebox");
message_request = message.createElement("request");
for (i=0; i