SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: Timer won't work
-
Sep 11, 2007, 10:45 #1
- Join Date
- Sep 2007
- Posts
- 76
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Timer won't work
Hi
I made a slideshow that works nicely but run into problems when I try to star/stop it.
I get this error: uncaught exception: [Exception... "Could not convert JavaScript argument" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://localhost/hydro.js :: <TOP_LEVEL> :: line 74" data: no]
Line 0
The code is below. Can anybody help?
Code:
var Pics = new Array();
Index = 0;
function LoadImages()
{
Pics[0] = new Image();
Pics[0].src = "UE Hydro Scheme 001.jpg";
.................................................. .......................
Pics[21] = new Image();
Pics[21].src = "Bonfirld Ghyll Hydro Bottom of Screw.jpg";
document.images[0].src = Pics[0].src;
}
/**/
Index1 = 0;
function SetTimer()
{
Timer = setInterval("Animate()", 3000);
}
function Animate ()
{
Index1 ++;
if (Index1 > 22) {
Index1 = 0;
};
document.images[0].src = Pics[Index1].src;
}
var start = document.getElementById("start");
addEventListener(start, "click", clickStart, false);
var stop = document.getElementById("stop");
addEventListener(stop, "click", clickStop, false);
function clickStart()
{
Timer = setTimeout("Animate()", 2075);
}
function clickStop () {
clearTimeout(Timer);
}
/CodeLast edited by gleb; Sep 11, 2007 at 10:59. Reason: Adding error message
-
Sep 11, 2007, 11:19 #2
- Join Date
- Jun 2007
- Location
- San Diego, CA
- Posts
- 784
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I think there are issues with...
Code:Timer = setInterval("Animate()", 3000);
Code:Timer = setInterval(Animate, 3000);
Whatever you can do or dream you can, begin it.
Boldness has genius, power and magic in it. Begin it now.
Chroniclemaster1, Founder of Earth Chronicle
A Growing History of our Planet, by our Planet, for our Planet.
-
Sep 11, 2007, 11:31 #3
- Join Date
- Apr 2006
- Posts
- 802
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The first problem is the way you are adding your event handlers-
use this syntax
Code:document.getElementById("start").addEventListener("click", clickStart, false); document.getElementById("stop").addEventListener("click", clickStop, false);
Code:if you want to include IE users you'll have to test the event object : if(document.attachEvent){ document.getElementById("start").attachEvent('onclick',clickStart); document.getElementById("stop").attachEvent('onclick',clickStop); } else if(document.addEventListener){ document.getElementById("start").addEventListener("click", clickStart, false); document.getElementById("stop").addEventListener("click", clickStop, false); }
-
Sep 12, 2007, 01:41 #4
- Join Date
- Sep 2007
- Posts
- 76
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Sep 12, 2007, 01:48 #5
- Join Date
- Sep 2007
- Posts
- 76
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I get the error 'ClickStart is not defined.
Thanks. I,know about the fix for IE but at the moment I'm just trying to get it to work in Firefox. The timer code now is
ClickStart: function()
{
Timer = setTimeout("Animate()", 2075);
}
ClickStop: function() {
clearTimeout(Timer);
}
var start= document.getElementById("start");
addEventListener(start, "click", ClickStart, false);
var stop = document.getElementById("stop");
addEventListener("click", ClickStop, false);
I get the error 'ClickStart is not defined.
Bookmarks