DHTML Lab - dhtmlab.com - Dynamic Headline Fader, Version 3.0 | 12 | WebReference

DHTML Lab - dhtmlab.com - Dynamic Headline Fader, Version 3.0 | 12


Dynamic Headline Fader, Version 3.0
IEmac 4.0 timer clearing

The Problem

When our Fader has run its course, and all loops are finished, and we stop the repeated calls to FDRdo() by using clearInterval(), IEmac 4.0 continues to call FDRdo().

That is, clearInterval() does not work. Neither does nulling the blendTimer variable in which we store the setInterval() method.

This bad behavior was fixed in later versions.

This behavior is not perceived by the user, since IEmac 4.0 continues to update the Fader with the final display. Nothing changes on the screen, although resources are being used.

The Solution

We are unable to prevent the repeated calls to FDRdo(). We can, however, stop FDRdo() from calling FDRend() repeatedly, when the Fader has finished looping. This will stop the unnecessary element updates and resource mongering.

To do this, we first need access to the blendTimer variable from all functions. It therefore gets declared as a global variable, early in our script:

blendTimer = null;

Later, in FDRstart(), we assign the setInterval() to blendTimer. This function remains unchanged, but is repeated here for reference:

function FDRstart(ind){
    newsCount = ind;
    if (FDRfinite) loopCount = 0;
    blendTimer = setInterval("FDRdo()",FDRblendInt*1000)

When the Fader has finished looping and FDRend() is called, we will once again give blendTimer a null value:

function FDRend(){

	blendTimer = null;

Therefore, when the timer is not being used, that is, before the Fader starts and after it is finished, blendTimer is null.

We can now test for the validity of repeated calls by checking the value of blendTimer. That is, if blendTimer is null, and our loop counter (loopCount) is not zero, it means the Fader should be finished. This test is made in the FDRdo() function, which IEmac 4.0 continues to call, mistakenly:

function FDRdo() {
	if(!blendTimer && loopCount>0) return;
    if (FDRfinite && loopCount==FDRmaxLoops) {
    if (newsCount == arNews.length) {
        newsCount = 0;
        if (FDRfinite) loopCount++;

If our test detects that the Fader should be finished, then FDRdo() returns, and doesn't call FDRend().

There, now IEmac 4.0 should work with our script! So, back to Navigator quirks.

Produced by Peter Belesis and

All Rights Reserved. Legal Notices.
Created: Nov 30, 1999
Revised: Nov 30, 1999

URL: http://www.webreference.com/dhtml/column27/fade3iemacintval.html