10 Replies Latest reply on May 15, 2006 6:09 AM by Peter Lorent

    Setting an interval

    exPluda? Level 1
      Hello,

      I made a simple function to simulate a typewriter, but now I want to define the speed of the effect, where do I need to add the interval?

      code:

      function escrever() {
      maquina = "FAZEMOS COM QUE ACONTEÇA";
      i = -1;
      l = "letras";
      espaco = 11;
      largura = 300;
      altura = 16;
      _root.onEnterFrame = function() {
      if (++i<maquina.length) {
      _root.createEmptyMovieClip("letras"+i, 20+i);
      letras = maquina.substr(i,1);
      _root["letras"+i].createTextField("letras"+i, 500+i, 0, 0, 20, 16);
      _root["letras"+i]["letras"+i].embedFonts = true;
      _root["letras"+i]["letras"+i].text = letras;
      _root["letras"+i]["letras"+i].selectable = false;
      _root["letras"+i]["letras"+i].setTextFormat(f);
      _root["letras"+i]._x = (i%largura)*espaco+10;
      _root["letras"+i]._y = 88.5;
      } else {
      this.onEnterFrame = null;
      }
      };
      }
      escrever();

      Thanks
        • 1. Re: Setting an interval
          Level 7
          The handler onEnterFrame is "invoked repeatedly at the frame rate of the SWF
          file." - http://livedocs.macromedia.com/flash/8/main/00002490.html

          For different speeds you might consider setInterval -
          http://livedocs.macromedia.com/flash/8/main/00001766.html.

          --
          Lon Hosford
          www.lonhosford.com
          May many happy bits flow your way!
          "exPluda?" <webforumsuser@macromedia.com> wrote in message
          news:e44pu5$1v$1@forums.macromedia.com...
          Hello,

          I made a simple function to simulate a typewriter, but now I want to define
          the speed of the effect, where do I need to add the interval?

          code:

          function escrever() {
          maquina = "FAZEMOS COM QUE ACONTE?A";
          i = -1;
          l = "letras";
          espaco = 11;
          largura = 300;
          altura = 16;
          _root.onEnterFrame = function() {
          if (++i<maquina.length) {
          _root.createEmptyMovieClip("letras"+i, 20+i);
          letras = maquina.substr(i,1);
          _root.createTextField("letras"+i, 500+i, 0, 0, 20, 16);
          _root.embedFonts = true;
          _root.text = letras;
          _root.selectable = false;
          _root.setTextFormat(f);
          _root._x = (i%largura)*espaco+10;
          _root._y = 88.5;
          } else {
          this.onEnterFrame = null;
          }
          };
          }
          escrever();

          Thanks


          • 2. Re: Setting an interval
            exPluda? Level 1
            Hello, thanks for reply,

            Yes, I nkow I need to use setInterval, I just don't know how or where to enter the setInterval function.

            Thanks
            • 3. Re: Setting an interval
              Peter Lorent Level 2
              Pluda, try:

              function escrever() {
              maquina = "FAZEMOS COM QUE ACONTEÇA";
              i = -1;
              l = "letras";
              espaco = 11;
              largura = 300;
              altura = 16;
              function typeText() {
              if (++i<maquina.length) {
              _root.createEmptyMovieClip("letras"+i, 20+i);
              letras = maquina.substr(i,1);
              _root["letras"+i].createTextField("letras"+i, 500+i, 0, 0, 20, 16);
              _root["letras"+i]["letras"+i].embedFonts = true;
              _root["letras"+i]["letras"+i].text = letras;
              _root["letras"+i]["letras"+i].selectable = false;
              _root["letras"+i]["letras"+i].setTextFormat(head_fnt);
              _root["letras"+i]._x = (i%largura)*espaco+10;
              _root["letras"+i]._y = 88.5;
              } else {
              clearInterval(typeInterval);
              }
              }
              typeInterval=setInterval(typeText,1000);
              }
              escrever();

              • 4. Re: Setting an interval
                exPluda? Level 1
                Perfect, thanks a lot LuigiL :-)
                • 5. Re: Setting an interval
                  Peter Lorent Level 2
                  You're welcome.
                  • 6. Re: Setting an interval
                    exPluda? Level 1
                    Hello,

                    Sorry for reopen this tread, but sometimes it seems my actionscript skills desapear...

                    Well, I'm trying to make function were I have a writing machine writing my slogan (this is working), but know I need to have a time (lets say 5 seconds) and I wan't to remove all the previous created movieclips and recreate them, a kind of loop.

                    what i'm doing wrong?

                    function escrever() {
                    maquina = "FAZEMOS COM QUE ACONTEÇA";
                    i = -1;
                    l = "letras";
                    espaco = 11;
                    largura = 300;
                    altura = 16;
                    function typeText() {
                    if (++i<maquina.length) {
                    _root.createEmptyMovieClip("letras"+i, 20+i);
                    letras = maquina.substr(i, 1);
                    _root["letras"+i].createTextField("letras"+i, 500+i, 0, 0, 20, 16);
                    _root["letras"+i]["letras"+i].embedFonts = true;
                    _root["letras"+i]["letras"+i].text = letras;
                    _root["letras"+i]["letras"+i].selectable = false;
                    _root["letras"+i]["letras"+i].setTextFormat(f);
                    _root["letras"+i]._x = (i%largura)*espaco+10;
                    _root["letras"+i]._y = 88.5;
                    filmes = _root["letras"+i];
                    } else {
                    clearInterval(typeInterval);
                    }
                    }
                    //
                    function remover() {
                    filmes
                    .removeMovieClip();
                    trace(filmes );
                    }
                    //
                    tirar = setInterval(remover, 250);
                    //
                    typeInterval = setInterval(typeText, 250);
                    }
                    //
                    repetir = setInterval(escrever, 250);

                    thanks a ton!
                    • 7. Re: Setting an interval
                      Peter Lorent Level 2
                      I would use somewhat different code. See attached.

                      • 8. Re: Setting an interval
                        Peter Lorent Level 2
                        textF.setTextFormat(head_fnt);

                        change that to:
                        textF.setTextFormat(f);
                        • 9. Re: Setting an interval
                          exPluda? Level 1
                          cool, very cool,

                          a diferent aproach with great results,

                          many thanks LuigiL :-)
                          • 10. Re: Setting an interval
                            Peter Lorent Level 2
                            You're welcome.