Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2003
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sending an Object using setInterval

    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)
    Thanks!
    Dan Bogaard
    Assistant Professor
    Information Technology
    Rochester Institute of Technology

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Location
    Surrey, UK
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Jan 2003
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...)
    Dan Bogaard
    Assistant Professor
    Information Technology
    Rochester Institute of Technology

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey Dan. I cover that topic in my as-of-yet-unpublished article. Look for it at SitePoint.com sometime soon

    Also, Algorithm wrote a nice JS class for handling timeouts/intervals that I've had nothing but success with.
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #5
    New to the CF scene
    Join Date
    Jan 2003
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Very cool!

    Thanks beetle!
    Dan Bogaard
    Assistant Professor
    Information Technology
    Rochester Institute of Technology


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •