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

N

Noggon

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);
 
L

Lasse Reichstein Nielsen

Noggon said:
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
 
N

Noggon

Lasse said:
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.
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.
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.
...

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top