By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,181 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

Help With setTimeout

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
"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

P: n/a
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.