SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    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);

    }
    /Code
    Last edited by gleb; Sep 11, 2007 at 10:59. Reason: Adding error message

  2. #2
    SitePoint Guru Chroniclemaster1's Avatar
    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);
    I believe it should be...

    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.

  3. #3
    SitePoint Guru
    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);
    }

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Chroniclemaster1 View Post
    I think there are issues with...

    Code:
    Timer = setInterval("Animate()", 3000);
    I believe it should be...

    Code:
    Timer = setInterval(Animate, 3000);
    Thanks but the animate bit is not the problem, it worked before I put the timer in.

  5. #5
    SitePoint Enthusiast
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •