Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setTimeout error, im lost

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
i have a recursive function to animate an object. It is defined as:

function MoveOBJ(OBJECT, x)
{
...
}

i was trying to use this line to recursivly call the function:

setTimeout('MoveOBJ(' + OBJECT + ', ' + x + ')', 50);

but it doesn't work. Although this line of code does work:

MoveOBJ(OBJECT, x);

Does anyone have any idea why the setTimeout code will not work?
 
setTimeout(("MoveOBJ(OBJECT, x)", 50);

try this ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
Thanks, but it doesn't work.

The error says OBJECT is undefined.
 
// oups should be [ponder]
setTimeout("MoveOBJ(OBJECT, x)", 50); ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
"The error says OBJECT is undefined"

where does OBJECT come from ? code ? ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
OBJECT is an argument in the function.

eg:

function MoveOBJ(OBJECT, x)
{
...
}

MoveOBJ('object1', 500);
 
where does 'object1' come from ? ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
u seem to have error passing the correct value to the object
but i can't guess here without anycode to see
but i assume "..." is correct ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
'object1' is the id of a <div>:

<div id = &quot;object1&quot;>
</div>
 
<script>
function MoveOBJ(OBJECT, x)
{
moveObjectBy(OBJECT, 10, 0);

obj = findDOM(OBJECT, 1);
var strCurrentX = obj.left;
var numCurrentX = parseInt(strCurrentX.substr(0,strCurrentX.length - 2));

if (numCurrentX < parseInt(x))
{
// setTimeout(&quot;MoveOBJ(OBJECT, x)&quot;, 50);
// setTimeout('MoveOBJ(' + OBJECT + ', ' + x + ')', 50);
MoveOBJ(OBJECT, x); //This one works
}
}
</script>

<div id=&quot;object1&quot; style=&quot;top: 0px; left: 0px;&quot;>
Hola
</div>

<script>
MoveOBJ('object1', 100);
</script>
 
Yes the code is fine, except for the recursive call...

PS: thanks for the help so far :-)
 
// here an example of interval function calling i use


function playandstop() {
if (lock == true) {
lock = false;
window.clearInterval(run);
} else if (lock == false) {
lock = true;
run = setInterval(&quot;next()&quot;, delay);
}
} ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
Ugg I figured out what it is...

since it is a string it required ' to surround it. So it should have been:

setTimeout(&quot;MoveOBJ(\'&quot; + OBJECT + &quot;\', &quot; + x + &quot;)&quot;, 50);

so it would send 'object1' instead of object1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top