PDA

View Full Version : FireWorks Script



cgweaver
02-03-2006, 05:15 PM
Here (http://www.javascript-fx.com/submitscripts/fireworks/fireworksImagePage/fw03.html)'s a really cool script that displays fireworks. (The script is within the source.) Unfortunately, the author did not allow for an easy and obvious way to set a time limit; they just keep going.

I would like to place a counter within the script that shuts it off after a number of iterations.

Twey
02-03-2006, 05:29 PM
The first thing you asked for was a timelimit. This can be achieved rather easily, like so:

window.setTimeout("myFW.stop()", 15000); // Turn off fireworks after 15 secondsTo end after a certain number of fireworks, replace the existing JSFX.FireWorkDisplay.prototype.animate() function with the following:


var numFireworks = 0;
JSFX.FireworkDisplay.prototype.animate = function()
{
if(numFireworks == 40) myFW.stop();
else numFireworks++;
status = this.loadCount;
if(this.loadCount < this.imgArray.length)
return;

for(var i=0 ; i<this.fireworks.length ; i++)
this.fireworks[i].animate();
}

cgweaver
02-03-2006, 08:15 PM
Thanks. I did not know about the setTimeout function. And I really appreciate knowing which function in the fireworks script contains the loop that I was looking for.