alcatraz678 (1) [Avatar] Offline
#1
Is this a bug or is it really designed this way?

net.CommandQueue = function(id,url, freq) {
this.id = id;
net.cmdQueues[id] = this;
this.url = url;
this.queued = new Array();
this.sent = new Array();
if(freq) {
this.repeat(freq);
}
}

net.CommandQueue.prototype.addCommand = function(command) {
if(this.isCommand(command)) {
this.queue.append(command,true);
}
}

net.CommandQueue.prototype.fireRequest = function() {
if (this.queued.length == 0) {
return;
}

var data = "data=";
for(var i = 0; i < this.queued.length; i++) {
var cmd = this.queued[i];
if(this.isCommand(cmd)) {
data += cmd.toRequestString();
this.sent[cmd.id] = cmd;
}
}
this.queued = new Array();
this.loader = new net.ContentLoader(this.url, net.CommandQueue.onload, net.CommandQueue.onerror, "POST",
data);
}

net.CommandQueue.prototype.isCommand = function(obj) {
return (
obj.implementsProp("id") &&
obj.implementsFunc("toRequestString") &&
obj.implementsFunc("parseResponse")
);
}

Object.prototype.implementsFunc = function(funcName) {
return this[funcName] && this[funcName] instanceof Function;
}

net.CommandQueue.onload = function(loader) {
var xmlDoc = net.req.responseXML;
var elDocRoot = xmlDoc.getElementsByTagName("commands")[0];
if(elDocRoot) {
for(i = 0; i < elDocRoot.childNodes.length; i++) {
elChild = elDocRoot.childNodes[i];
if(elChild.nodeName == "command") {
var attrs = elChild.attributes;
var id = attrs.getNamedItem("id").value;
var command = net.CommandQueue.sent[id];
if(command) {
command.parseResponse(elChild);
}
}
}
}
}

net.CommandQueue.onerror = function(loader) {
alert("problem sending the data to the server");
}

net.CommandQueue.prototype.repeat = function(freq) {
this.unrepeat();
if(freq>0) {
this.freq = freq;
var cmd = "net.cmdQueues["+this.id+"].fireRequest()";
this.repeater = setInterval(cmd, freq*1000);
}
}

net.CommandQueue.prototype.unrepeat = function() {
if(this.repeater) {
clearInterval(this.repeater);
}
this.repeater = null;
}

this.queue is not an array and doesn't seem to be used in other codes.
Is this a wrong type or is it really designed this way?
it bugs me because im still a beginner..

Thanks