...

View Full Version : Passing Functions Array Objects



rpmusic
08-26-2002, 02:05 PM
I'm trying to generic 'atise the following DHTM/Javascript scrolling window function.
The function gets passed an array Object which contains the id of the scrolling DIV layer.
It works on the first passing, however this line -

scrTmId = setTimeout("scrollDown("+wndo+","+num+","+inc+")",scrTimer);

results in an javascript error "] expected"

I can't work out how to pass back the orginal refernce to the function

The full page can we see at www.rarepleasures.co.uk/index2.htm

function scrollDown(wndo,num,inc) {
if (!pgLoaded) return;
var y = parseInt(wndo[num].cnt.css.top);

if (y>-wndo[num].maxY) {
wndo[num].cnt.shiftBy(0,-inc);
scrTmId = setTimeout("scrollDown("+wndo+","+num+","+inc+")",scrTimer);
}
}

premshree
08-26-2002, 02:52 PM
See this thread :
http://www.codingforums.com/showthread.php?threadid=4543&highlight=setTimeout

rpmusic
08-26-2002, 03:07 PM
I've tried those methods, but the object still doesn't get passed back to the function and I generate the same error.

RoyW
08-26-2002, 04:13 PM
You cannot pass objects in the setTimeout function. The most you can pass are primitives such as numbers or strings. The way to do it is to pass the name of the object then use the window object to gain access to your array object. Try this code


function scrollDown(wndName,num,inc) {
if (!pgLoaded) return;

var wndo = window[wndName];
var y = parseInt(wndo[num].cnt.css.top);

if (y>-wndo[num].maxY) {
wndo[num].cnt.shiftBy(0,-inc);
scrTmId = setTimeout("scrollDown('"+wndName+"',"+num+","+inc+")",scrTimer);
}
}
function scrollUp(wndName,num,inc) {
if (!pgLoaded) return;

var wndo = window[wndName];
var scrollDiv = wndo[num];
var y = parseInt(wndo[num].cnt.css.top);

if (y<0) {
scrollDiv.cnt.shiftBy(0,inc);
scrTmId = setTimeout("scrollUp('"+wndName+"',"+num+","+inc+")",scrTimer);
}
}


You then change the onmouseover to


onmouseover="scrollUp('gigs',0,4);
onmouseover="scrollDown('gigs',0,4);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum