1 Reply Latest reply on Aug 28, 2011 6:49 AM by kglad

    Metronome

    S Per E K

      I tried to build a metronome in Flash AS2 with a rather lousy result because it won't keep the pace which would have been a suitable feature for a metronome. I tried a few different methods to do the sync with actionscript. I even tried to put the sound in the timeline but it didnt work any better of course. Here is the code:

      ------------

      AS2 with constant tempo 200 ms, based on the onEnterFrame handler, framerate set to 5 fps:

       

      var soundObject:Sound = new Sound ();

      soundObject.attachSound ("snd");

      this.onEnterFrame = function () {

           soundObject.start ();

      };

      ------------

      AS2 with variable tempo from an input text field "intervalField", based on the Interval function. The functions "run" and "stopRun" is trigged by buttons. Framerate set to 100 to get the sound to update as often as possible:

       

      var intervalId:Number;

      var duration:Number;

      var soundObject:Sound = new Sound ();

      soundObject.attachSound ("snd");

      function run () {

           clearInterval(intervalId);

           duration = Number (intervalField.text);

           intervalId = setInterval (this, "stimuli", duration);

      }

      function stopRun () {

           clearInterval(intervalId);

      }

      function stimuli () {

           soundObject.start ();

      }

      ------------

       

      Here are my failures in some variations if someone would like to listen which I doubt. (Pardon the swedish text there, "otakt" means out of pace and thats the name of this metronome application ha ha ha).

      http://www.pellekarlsson.eu/otakt/otaktlinks.html

       

       

      Thanks

        • 1. Re: Metronome
          kglad Adobe Community Professional & MVP

          flash can't be used for precise timing.  about the best you could do would be to keep the timing within 5%.  if that's good enough for you, increase your fps to 50 and see if that's good enough.