[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 442
  • Last Modified:

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

0
rgarimella
Asked:
rgarimella
1 Solution
 
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
 
HonorGodCommented:
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now