//Countdown Class by Sean Christmann developer@mustardlab.com /* class CountDown(instancename) parameters instancename - the instance of an object loading content, example objects include _root, MovieClip instances, LoadVars instances, etc... example mytimer = new CountDown(_root); method getSecondsLeft(finishbytes) parameters finishbytes - the byte value for when the countdown timer should reach zero, default is getBytesTotal() returns the number of seconds left until the specified object has loaded method setDefault(char) parameters char - a char value to display while the CountDown class spends 1 second determining average loading time, default is "-" returns nothing */ _global.CountDown = function(obj) { this.refobj = obj; this.startbytes = this.refobj.getBytesLoaded(); this.lastbytes = this.refobj.getBytesLoaded(); this.avgbytes = 0.1; this.nullchar = "-"; this.secs = 0; this.runAvg = function() { this.secs++; this.loadedbytes = this.refobj.getBytesLoaded(); this.avgbytes = (((this.loadedbytes-this.startbytes)/this.secs)*0.7)+((this.loadedbytes-this.lastbytes)*0.3); this.lastbytes = this.loadedbytes; if (this.loadedbytes>=this.refobj.getBytesTotal()) clearInterval(this.interv); }; this.interv = setInterval(this, "runAvg", 1000); }; CountDown.prototype.getSecondsLeft = function(finishbytes) { if (!finishbytes.length || finishbytes>this.refobj.getBytesTotal()) var finishbytes = this.refobj.getBytesTotal(); var secsleft; var bytesleft = finishbytes-this.loadedbytes; if (this.secs == 0) { secsleft = this.nullchar; }else if (bytesleft>0) { secsleft = Math.ceil(bytesleft/this.avgbytes); } else { secsleft = 0; } return secsleft; }; CountDown.prototype.setDefault = function(char) { this.nullchar = char; };