3 Replies Latest reply on Jun 24, 2008 4:14 PM by Craig Grummitt

    flex Timer is not accurate?

    softsafari
      I've set up a basic timer as follows

      private function SetUpTimer():void
      {

      _timer = new Timer(2,20);
      _timer.addEventListener(TimerEvent.TIMER,dummy);
      _timer.start();

      }

      and this function calls the below

      private function dummy(e:TimerEvent):void
      {

      var d:Date = new Date();
      txtMsg.text += d.getSeconds().toString() +":" + d.getMilliseconds().toString() +" ";
      }

      Since the timer interval was setup for 2 millisecond intervals you would expect to see 2 millisecond intervals in the interface as it is updated. For intance,
      txtMsg.text += d.getSeconds().toString() +":" + d.getMilliseconds().toString() +" ";

      would show a difference of 2 milliseoncs between events. But the values I get in the textbox are the following

      26:265 26:281 26:296 26:312 26:328 26:343 26:359 26:421 26:484 26:515 26:531 26:546 26:562 26:578 26:593 26:609 26:625 26:640 26:656 26:671

      As you can see there is a HUGE difference between intervals. Huge in the sense of what I want to do which is play a portion of an mp3 clip. For example if I have an mp3 clip and I want to play a portion from lets say 1.234 seconds to 1.935 seconds it always runs past this limit because of the timer so rather than stopping at 1.935 it will stop at 1.950 for instance...

      So for instance I play a portion of a clip as follows

      private function playPortion():void
      {
      _timer = new Timer(2);
      _timer.addEventListener(TimerEvent.TIMER,stopPlay);
      _timer.start();
      _soundChannel = _sound.play( startPos);

      }

      private function stopPlay(e:TimerEvent):void
      {
      if ( (uint(_soundChannel.position.toFixed(0))) >= stopPoint)
      {
      _soundChannel.stop();
      _timer.stop();

      }

      }

      This never stops on time since the timer interval is not precise... Can anyone see what I'm doing wrong or is ther any other way to play a portion of an mp3 clip giving the start and stop positions in milliseconds?