Skyzyx
04-12-2003, 12:06 AM
I'm re-writing one of my message ticker scripts as an object. The problem is that once a variable is initialized as a new instance of my object, it can't seem to reference an internal function (this.functionName()) without causing an error.
Here's a snippet:
function messageCenter(spanId, delayInMS)
{
. . .
// Start Messages.
this.start=function(startWhere)
{
current=(startWhere) ? startWhere:0;
document.getElementById(this.spanId).innerHTML=mcMessages[current];
if (current == mcMessages.length-1) current=0;
else current++;
// The bug is with the line below
var tOut=setTimeout("this.start()", this.delay);
}
. . .
}
// Create a new instance of the object.
var msg=new messageCenter('show');
// Add the messages. This works.
msg.addMessage('What do you want?');
msg.addMessage('Hmmm...');
msg.addMessage('All your mother are belong to us.');
//-->
</script>
</head>
<!-- Load the ticker after body has loaded -->
<body onload="msg.start();">
It doesn't seem to want to recursively call itself, since this.start() is now msg.start().
I've included the entire script here. I believe it all works, other than this recursive part.
Here's a snippet:
function messageCenter(spanId, delayInMS)
{
. . .
// Start Messages.
this.start=function(startWhere)
{
current=(startWhere) ? startWhere:0;
document.getElementById(this.spanId).innerHTML=mcMessages[current];
if (current == mcMessages.length-1) current=0;
else current++;
// The bug is with the line below
var tOut=setTimeout("this.start()", this.delay);
}
. . .
}
// Create a new instance of the object.
var msg=new messageCenter('show');
// Add the messages. This works.
msg.addMessage('What do you want?');
msg.addMessage('Hmmm...');
msg.addMessage('All your mother are belong to us.');
//-->
</script>
</head>
<!-- Load the ticker after body has loaded -->
<body onload="msg.start();">
It doesn't seem to want to recursively call itself, since this.start() is now msg.start().
I've included the entire script here. I believe it all works, other than this recursive part.