Help With setTimeout

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dennis M. Marks

    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.getEle mentById('train Division').styl e.left = MenuX+"px";
    }
    else {
    eval(Lq+'trainD ivision'+Sq+'.l eft=MenuX');
    }
    setTimeout('mov eTrain()',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! =-----
  • Dennis M. Marks

    #2
    Re: Help With setTimeout- Please Ignore

    In article <13122003172138 5541%denmarks@d csi.net>, Dennis M. Marks
    <denmarks@dcsi. net> wrote:
    [color=blue]
    > 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.getEle mentById('train Division').styl e.left = MenuX+"px";
    > }
    > else {
    > eval(Lq+'trainD ivision'+Sq+'.l eft=MenuX');
    > }
    > setTimeout('mov eTrain()',speed );
    > }
    > ///
    > }[/color]


    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! =-----

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: Help With setTimeout

      "Dennis M. Marks" <denmarks@dcsi. net> writes:
      [color=blue]
      > There is no problem with the following function.[/color]

      I can see some ;)
      [color=blue]
      > 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.[/color]

      Either put it after an "else" or put a return after the call to
      "setTimeout ".
      [color=blue]
      > What happens after the setTimeout?[/color]

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


      Now for the comments:
      [color=blue]
      > function moveTrain() {
      > if (MenuX < PosX) {
      > MenuX = MenuX + increment;
      > if (is_NS5up) {[/color]

      Browser detection is rarely safe. You should test for the existence
      of the features you use instead:

      if (document.getEl ementById) {
      [color=blue]
      > document.getEle mentById('train Division').styl e.left = MenuX+"px";
      > }
      > else {
      > eval(Lq+'trainD ivision'+Sq+'.l eft=MenuX');[/color]

      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=Men uX+"px";
      } else if (document.layer s) {
      document.layers['trainDivision'].left = MenuX;
      } else { //panic and try something desperate:
      window['trainDivision'].left = MenuX;
      }
      [color=blue]
      > }
      > setTimeout('mov eTrain()',speed );
      > }
      > ///[/color]
      else {
      ///
      }

      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • Dennis M. Marks

        #4
        Re: Help With setTimeout

        In article <iskkuo17.fsf@h otpop.com>, Lasse Reichstein Nielsen
        <lrn@hotpop.com > wrote:
        [color=blue]
        > "Dennis M. Marks" <denmarks@dcsi. net> writes:
        >[color=green]
        > > There is no problem with the following function.[/color]
        >
        > I can see some ;)
        >[color=green]
        > > 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.[/color]
        >
        > Either put it after an "else" or put a return after the call to
        > "setTimeout ".
        >[color=green]
        > > What happens after the setTimeout?[/color]
        >
        > The next line, just as any other function call. Calls to "setTimeout "
        > returns instantly, and evaluation continues.
        >
        >
        > Now for the comments:[/color]
        (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! =-----

        Comment

        Working...