function TweenEngine(){ this.executionInterval = 33; this.curIndex = 0; this.commandQueue = []; this.isRunning = false; } TweenEngine.prototype.startEngine = function(method,obj,params){ this.isRunning = true; this.intervalId=setInterval(this,"runNextCommand",this.executionInterval); return true; } TweenEngine.prototype.stopEngine = function(){ this.isRunning = false; if(this.intervalId!=undefined){ clearInterval(this.intervalId); return delete this.intervalId; } else return false; } TweenEngine.prototype.addCommand = function(meth,obj,params){ this.commandQueue.push({meth: meth, obj: obj, params: params}); return true; } TweenEngine.prototype.addCommands = function(commands){ this.commandQueue = this.commandQueue.concat(commands); return true; } TweenEngine.prototype.setExecutionInterval = function(interval){ this.executionInterval = interval; if(this.isRunning){ this.stopEngine(); this.startEngine(); return true; }else{ return true; } } TweenEngine.prototype.runNextCommand = function(){ var cmd; var rtn = false; cmd = this.commandQueue[this.curIndex]; rtn = cmd.obj[cmd.meth].apply(cmd.obj,cmd.params); if(!rtn) this.curIndex++; if(this.curIndex >= this.commandQueue.length) { this.curIndex = 0; if(this.isRunning)this.stopEngine(); return false; } return true; }