function calls coming back as undefined when using setTimeout to fetch them?

Discussion in 'Javascript' started by Noggon, Jun 24, 2006.

  1. Noggon

    Noggon Guest

    My function, called first() keeps coming back to me in the javascript
    console as being undefined.

    Yet I can't think why it isn't loaded. Maybe I'm brain dead, so could
    use some help! :)

    What I'm trying to do is to have functions call each other at intervals
    of 2 seconds, each changin a src of an image as they do so.


    function first()
    {
    picturePlace.src =
    "movie_info_data/godfather_info/godfather_listening.jpg";
    window.setTimeout("second()",2000);
    }

    function second()
    {
    picturePlace.src =
    "movie_info_data/godfather_info/godfather_deepinthought.jpg";
    window.setTimeout("third()",2000);
    }

    function third()
    {
    picturePlace.src =
    "movie_info_data/godfather_info/godfather_dancingdaughter.jpg";
    window.setTimeout("fourth()",2000);
    }

    function fourth()
    {
    picturePlace.src =
    "movie_info_data/godfather_info/godfather_withson.jpg";
    }

    window.setTimeout("first()",2000);
     
    Noggon, Jun 24, 2006
    #1
    1. Advertising

  2. Re: function calls coming back as undefined when using setTimeoutto fetch them?

    "Noggon" <> writes:

    > My function, called first() keeps coming back to me in the javascript
    > console as being undefined.


    I guess it's true then :).

    You say "javascript console". What browser are you using? Sounds like
    a Mozilla and/or Firefox browser.

    > What I'm trying to do is to have functions call each other at intervals
    > of 2 seconds, each changin a src of an image as they do so.


    Another approach is to use setInterval on just one function, and then
    increment a counter for each invocation.


    > function first()


    Where is this code located?
    Is it inside another function?
    In your duplicate message it seems it is inside a switch statement,
    but it's not obvious what context that is in.

    ....
    > window.setTimeout("first()",2000);


    This requests that the expression "first()" is executed in the global
    context in two seconds.

    If the "first" function is not declared in the global scope, then this
    fails.

    Another approach is:
    window.setTimeout(first, 2000);
    which requests that the function value that "first" evaluates to is
    executed in two seconds.



    Scope rules is (another) good reason why working with expressions in
    strings is so errorprone.
    /L
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Jun 25, 2006
    #2
    1. Advertising

  3. Noggon

    Noggon Guest

    Lasse Reichstein Nielsen wrote:
    > "Noggon" <> writes:
    >
    > > My function, called first() keeps coming back to me in the javascript
    > > console as being undefined.

    >
    > I guess it's true then :).
    >
    > You say "javascript console". What browser are you using? Sounds like
    > a Mozilla and/or Firefox browser.


    The Firefox. It isn't 1.5, thanks to some difficulties downloading
    extensions.

    > > What I'm trying to do is to have functions call each other at intervals
    > > of 2 seconds, each changin a src of an image as they do so.

    >
    > Another approach is to use setInterval on just one function, and then
    > increment a counter for each invocation.


    I should try that some time. I seriously need to learn some algorithims
    for this stuff.

    >
    > > function first()

    >
    > Where is this code located?
    > Is it inside another function?
    > In your duplicate message it seems it is inside a switch statement,
    > but it's not obvious what context that is in.


    I'm passed "this" referances from click events on different span tags.
    I decide which group of images to use depending on how the referance is
    named.

    > ...
    > > window.setTimeout("first()",2000);

    >
    > This requests that the expression "first()" is executed in the global
    > context in two seconds.
    >
    > If the "first" function is not declared in the global scope, then this
    > fails.


    Ah, I think I'm begining to see the light.

    > Another approach is:
    > window.setTimeout(first, 2000);
    > which requests that the function value that "first" evaluates to is
    > executed in two seconds.


    God, you know I've searched my entire javascript book for this
    information in the past, and never did it once explain that.

    So thanks. :)

    >
    > Scope rules is (another) good reason why working with expressions in
    > strings is so errorprone.


    No kidding, cheers.
     
    Noggon, Jun 25, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leon
    Replies:
    5
    Views:
    822
  2. Steve Holden

    PyCon is Coming! PyCon is Coming!

    Steve Holden, Jan 5, 2006, in forum: Python
    Replies:
    0
    Views:
    336
    Steve Holden
    Jan 5, 2006
  3. Biranchi Narayan Panda
    Replies:
    0
    Views:
    583
    Biranchi Narayan Panda
    Feb 21, 2010
  4. Noggon
    Replies:
    1
    Views:
    138
    Noggon
    Jun 24, 2006
  5. Bob
    Replies:
    5
    Views:
    290
Loading...

Share This Page