Skip to main content
Inspiring
April 3, 2007
Answered

setInterval scope

  • April 3, 2007
  • 2 replies
  • 216 views
Yo.

Working on a simple image fade in, fade out routine here. Standard setInterval use to run through an array of images. The code works beautifully until I inserted it into my SWindow class.

Its pretty simple actually. When the media container is created, the first image is loaded and then setInterval is called to cycle through the images....pretty standard stuff. But here's where it goes funny. The trace statements inside nextImage return undefined. They are member functions of the class so I'd have thought that scope was good but apparently it is not.

I've tried sending setInterval a reference to my SWindow class among other things. The result is no execution of the nextImage call at all but no errors are reported. I've provided the code for the three functions in question. I've tested the code outside of a class....it's from my repository....and I know it works. I am only having problems after the code is inside a class. Any help, pointers, or simple slaps in the head for missing something easy are all appreciated at this point.

Mike

This topic has been closed for replies.
Correct answer Peter Lorent
The syntax in classes is somewhat different.
intervalID=setInterval(this,"nextImage", 5000);

2 replies

SymTsbAuthor
Inspiring
April 3, 2007
Luigi you are a wonderful man. Thank you! Problem solved.
Peter LorentCorrect answer
Inspiring
April 3, 2007
The syntax in classes is somewhat different.
intervalID=setInterval(this,"nextImage", 5000);