Set Interval Clear Interval

Hi Folks,

I have the following code that I want to run, till the preloader is at 100% and set the clear Interval, so that the function is not called. The code below consistently runs the gotoFrameNo function.

The clearInterval is not called. Any ideas!!

RG
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>SetInterval Test</title>
<script type="text/javascript">
function curSlideNo(){		  
  var myMovie = CaptivateController("captivateSample");
  var curSlideNumber = myMovie.query("rdinfoCurrentSlide");
  alert ("Current Slide > " + curSlideNumber);
}
	
	
function runit(){
  var ct = setInterval( function(){ gotoFrameNo(15); } ,1000);
}
	
function gotoFrameNo(frameNo){
  var myMovie = CaptivateController("captivateSample");
  var loadedNum = myMovie.percentLoaded();
  if (loadedNum == 100){
    clearInterval(ct);
    var slide = myMovie.query("rdinfoCurrentSlide");
    myMovie.gotoSlideAndPlay(frameNo);
  }
}
		
</script>
</head>
<body onLoad="runit();" onbeforeUnload="curSlideNo();">
   <div id="captivateSample"></div>
</body>
</html>

Open in new window

rgarimellaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
Hello rgarimella,

To debug try :

(you may correct line 19 too by :if (loadedNum >= 99) {
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>SetInterval Test</title>
<script type="text/javascript">
function curSlideNo(){            
  var myMovie = CaptivateController("captivateSample");
  var curSlideNumber = myMovie.query("rdinfoCurrentSlide");
  alert ("Current Slide > " + curSlideNumber);
}
        
        
function runit(){
  var ct = setInterval( function(){ gotoFrameNo(15); } ,1000);
}
        
function gotoFrameNo(frameNo){
  var myMovie = CaptivateController("captivateSample");
  var loadedNum = myMovie.percentLoaded();
  if (loadedNum >= 100){
    clearInterval(ct);
    var slide = myMovie.query("rdinfoCurrentSlide");
    myMovie.gotoSlideAndPlay(frameNo);
  }
  document.getElementById("debugsection").innerHTML = loadedNum;
}
                
</script>
</head>
<body onLoad="runit();" onbeforeUnload="curSlideNo();">
   <div id="captivateSample"></div>
<br /><div id="debugsection"></div>
</body>
</html>

Open in new window

0
rgarimellaAuthor Commented:
Didnt work. I also do not see anything in debugsection
0
HonorGodSoftware EngineerCommented:
Like this?
<html>
<body>

<script type='text/javascript'>
  var timerid = null;

  function field( id ) {
    var ele = document.getElementById( id );
    if ( !ele ) {
      alert( 'Specified element not found. id="' + id + '"' );
    }
    return ele;
  }

  function start() {
    if ( timerid ) {
      window.clearInterval( timerid );
    }
    timerid = window.setInterval( 'update()', 1000 );
  }

  function stop() {
    if ( timerid ) {
      window.clearInterval( timerid );
    }
    timerid = null;
    var here = field( 'here' );
    if ( here ) {
      here.innerHTML = '';
    }
  }

  function update() {
    var here = field( 'here' );
    if ( here ) {
      here.innerHTML = new Date();
    }
  }
</script>
<input type='button' value='start' onclick='start()'><br>
<input type='button' value='stop' onclick='stop()'>
<div id='here'></div>

</body>
</html>

Open in new window

0
jetcookCommented:
define "ct" in global, do not define it in function.

var ct = null;
function runit(){
}

-OR-
window.ct = setInterval ...

clearInterval(window.ct)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.