View Full Version : Sending an Object using setInterval

04-11-2003, 04:35 PM
Hello again...

I was wondering if anyone knew of a problem sending an object to a function using setInterval?
If I call a function normally:

testMissle(firing, event.clientX, event.clientY);

It works fine, but if I try it with setInterval:

var intervalID=setInterval("testMissle(firing, event.clientX, event.clientY)", 10);

I get an error inside of the function:

function testMissle(obj, destX, destY)
{ alert(obj);

on the alert that obj is not defined...

Anyone heard of this? (let me know if you need to see more code)

04-11-2003, 06:24 PM
if firing is not the name of global variable it won't work. The expression for setTimeout is a String passed to the window object for execution aftre the second param(in milliseconds), so you must either represent finally as a String recognisable by the window object(not by the function declaring firing), or make firing a global var if you can.

04-11-2003, 10:15 PM
Thanks so much...

I didn't have my object declared in the global object, just in another function - your suggestion did the trick! (didn't know that setInterval - and assuming setTimeout is the same - looked to the global object for the values being passed in...)

04-11-2003, 10:30 PM
Hey Dan. I cover that topic in my as-of-yet-unpublished article (http://www.peterbailey.net/test/article.htm). Look for it at SitePoint.com sometime soon

Also, Algorithm wrote a nice JS class (http://www.codingforums.com/showthread.php?s=&threadid=10531) for handling timeouts/intervals that I've had nothing but success with.

04-11-2003, 10:32 PM
Very cool!

Thanks beetle!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum