4 Replies Latest reply on Feb 15, 2007 1:57 AM by Christopher Barnard

    setInterval ()

    Christopher Barnard Level 1
      Hope you can help.

      I have created four functions (func_1, func_2, func_3, func_4) in an external file. I want these functions to be excuted after a set time, and of course I have looked to setInterval to acheive this.

      The problem is I have never used setInternal in this specific way - I can use it so attach a movie or a random movie, but not to call a function from an external file.

      All I want to do is to loop through the 4 functions. I tried this, with some success:

      delay = 6000;

      a = setInterval(func_1, delay);
      clearInterval(a)
      b = setInterval(func_2, delay);
      clearInterval(b)
      c = setInterval(func_3, delay);
      clearInterval(c)
      d = setInterval(func_4, delay);
      clearInterval(d)

      function func_1 (a)
      {}

      function func_2 (b)
      {}

      function func_3 (c)
      {}

      function func_4 (d)
      {}

      As mentioned, this worked to an extent but it would only call the last variable 'd' and would not loop sequentially through the functions a, b, c.

      I hope you understand and can help.

      Regards

      Chris
        • 1. setInterval ()
          macdaddy256
          Chris - not sure what the cope is on your code, but here's a little class to run four functions - not necessarily the easiest way, but I think it explains things much better. To do anything useful, you'll probably have to pass a reference to wherever you're caling from.

          set up with:

          import FunctionSquence;
          var mySequence:FunctionSequence = new FunctionSequence(6000);

          then run the functions with:

          mySequence.runFunctions();

          • 2. Re: setInterval ()
            Christopher Barnard Level 1
            Thanks for the reply. Predictably I get the class running but I have no idea how to pass a reference to call my functions.

            Is there any advice on this you can give.

            Thanks again! :-)
            • 3. Re: setInterval ()
              macdaddy256 Level 1
              Is everything else happening on the _root timeline, or in movieClips? From your question I'm assuming it is. I only really put the answer in a class as that's a more comfortable scope model, and you mentioned 'external files' - the code below will work from the main timeline or a movieClip, so you can just use the 'this' keyword to get the functions working (see function 1).

              If you still want the class, let me know.
              • 4. Re: setInterval ()
                Christopher Barnard Level 1
                Thanks a million,

                I got that working very nicely.

                When I was talking about external files, I wasn't being very explicit - I meant keeping the code in external .as files, therefore I had four functions, doing slightly different things - (in a way). I was trying to call each one of those functions after a set interval - but I couldn't do it, unless I just triggered them on the _root timeline. But I'm trying to approach everything in a more professional manner these days!

                I do need to learn how to use it is a class though. If that makes any sense.

                Chris