469,909 Members | 1,630 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,909 developers. It's quick & easy.

Help With setTimeout

There is no problem with the following function. I want to insert code
at the point that the function does not repeat. I was pretty sure that
it could be inserted at the /// but that repeats with every loop. What
happens after the setTimeout? Does the flow continue through the bottom
of the function every time? How can I trap it on the last loop?
function moveTrain() {
if (MenuX < PosX) {
MenuX = MenuX + increment;
if (is_NS5up) {
document.getElementById('trainDivision').style.lef t = MenuX+"px";
}
else {
eval(Lq+'trainDivision'+Sq+'.left=MenuX');
}
setTimeout('moveTrain()',speed);
}
///
}

--
Dennis M. Marks
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 20 '05 #1
3 1298
In article <13*************************@dcsi.net>, Dennis M. Marks
<de******@dcsi.net> wrote:
There is no problem with the following function. I want to insert code
at the point that the function does not repeat. I was pretty sure that
it could be inserted at the /// but that repeats with every loop. What
happens after the setTimeout? Does the flow continue through the bottom
of the function every time? How can I trap it on the last loop?
function moveTrain() {
if (MenuX < PosX) {
MenuX = MenuX + increment;
if (is_NS5up) {
document.getElementById('trainDivision').style.lef t = MenuX+"px";
}
else {
eval(Lq+'trainDivision'+Sq+'.left=MenuX');
}
setTimeout('moveTrain()',speed);
}
///
}

It looks like there is no practical way to start a sound using
javascript that will work on most browsers therefore I don't need a way
to insert commands.

--
Dennis M. Marks
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 20 '05 #2
"Dennis M. Marks" <de******@dcsi.net> writes:
There is no problem with the following function.
I can see some ;)
I want to insert code at the point that the function does not
repeat. I was pretty sure that it could be inserted at the /// but
that repeats with every loop.
Either put it after an "else" or put a return after the call to
"setTimeout".
What happens after the setTimeout?
The next line, just as any other function call. Calls to "setTimeout"
returns instantly, and evaluation continues.
Now for the comments:
function moveTrain() {
if (MenuX < PosX) {
MenuX = MenuX + increment;
if (is_NS5up) {
Browser detection is rarely safe. You should test for the existence
of the features you use instead:

if (document.getElementById) {
document.getElementById('trainDivision').style.lef t = MenuX+"px";
}
else {
eval(Lq+'trainDivision'+Sq+'.left=MenuX');
You don't need eval for this. I don't know what Lq and Sq are, but you
never need to use eval for accessing properties or variables. It is
slow, inefficient, and hard to debug.

How about:
if (document.all) {
document.all['trainDivision'].style.left=MenuX+"px";
} else if (document.layers) {
document.layers['trainDivision'].left = MenuX;
} else { //panic and try something desperate:
window['trainDivision'].left = MenuX;
}
}
setTimeout('moveTrain()',speed);
}
///

else {
///
}

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
In article <is**********@hotpop.com>, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
"Dennis M. Marks" <de******@dcsi.net> writes:
There is no problem with the following function.


I can see some ;)
I want to insert code at the point that the function does not
repeat. I was pretty sure that it could be inserted at the /// but
that repeats with every loop.


Either put it after an "else" or put a return after the call to
"setTimeout".
What happens after the setTimeout?


The next line, just as any other function call. Calls to "setTimeout"
returns instantly, and evaluation continues.
Now for the comments:

(snip>
Thank you for the information and comments. This was part of a script
that I found on a javascript site. It was for a slide out menu. I am
modifing but not rewriting it to have a train move across the screen
and stop in the middle. I wanted to say "all aboard" when it stopped
and needed a place to insert the code.

I have not been able to find a way to have a sound start using a
script. Can anyone help? I will use "else" if I can find code.

--
Dennis M. Marks
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Brandon Hoppe | last post: by
4 posts views Thread by Mool | last post: by
2 posts views Thread by Jackson Yap | last post: by
12 posts views Thread by Andrew Poulos | last post: by
4 posts views Thread by E | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.