Timer won't work

This is a discussion on "Timer won't work" within the JavaScript Forum section. This forum, and the thread "Timer won't work are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Sep 11th, 2007, 17:42
New Member
Join Date: Sep 2007
Location: yorkshire
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Timer won't work

Hi
I made a slideshow that works nicely but run into problems when I try to star/stop it. The code is below.
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]

Can anybody help?

Code:
Code: Select all
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 karinne; Sep 12th, 2007 at 12:17. Reason: Please use the vBcode [ code ] when inserting code in your post.
Reply With Quote

  #2 (permalink)  
Old Sep 12th, 2007, 08:43
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Timer won't work

the timeout reference Timer is being declared inside of a function so it doesn't have the scope to be used in another function.

Declare the variable into the global space with var Timer; (outside of any functions)

This means that all functions can use it.

Cheers,
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
Reply

Tags
images, timer

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
1st timer hosting questions jimbaines Hosting & Domains 16 Jun 21st, 2007 11:27
1st Timer Here, Back in the game allrightythen Introduce Yourself 7 Jun 19th, 2007 01:17
Javascript Timer spinal007 JavaScript Forum 0 Apr 1st, 2007 15:02
request for help in countdown timer thebmwz4 Classic ASP 4 Sep 4th, 2005 14:45
Self Updating Timer. Amin PHP Forum 4 Jun 24th, 2005 18:37


All times are GMT. The time now is 10:37.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43