Trouble With Timers

Hello, I’m an absolute beginner so I’d appreciate it if you could bear with me. I’ve been having problems with some code that should execute a function periodically at certain intervals, say, every 5 seconds. Having tried to accomplish this with a timer it seems to wait for the duration of time specified in the timer, then execute the function constantly with no pause.

Here’s my code, the offending segment being the onstart function and the timer: tm. I’ll include a related class in case the issue lies within that as I haven’t much of a clue.


var sfx_gun:Sound = new sfx();
var sp:MovieClip = new Player;
var tm:Timer = new Timer(5000);

tm.addEventListener(TimerEvent.TIMER, onstart);

var bulletholder:Sprite = new Sprite();

addChild(bulletholder);

stage.addEventListener(MouseEvent.CLICK,onclick);

tm.start();
function onstart(e:Event){
 var em:Sprite = new enemy();
 em.y= Math.random()*600;
 addChild(em);
 }
function onclick(e:Event) {
 sfx_gun.play();
 sp.y=_player.y-67.9;
 sp.x=_player.x-10;
 var bl:Sprite = new bullet();
 bl.y=sp.y;
 bl.x=sp.x;
 bulletholder.addChild(bl);
}

Enemy Class

package {
 import flash.events.Event;
 import flash.display.MovieClip;
 import flash.display.Sprite;
 public class enemy extends Sprite {
  private var core:Object;
  public function enemy() {
   addEventListener(Event.ADDED_TO_STAGE,onadd);
  }
  
  private function onadd(e:Event) {
   core=MovieClip(root);
   addEventListener(Event.ENTER_FRAME,loop);
  }
  
  private function loop(e:Event) {
   x+=6;
   for (var i:int = 0; i<core.bulletholder.numChildren; i++) {
    var bulletTarget:Sprite=core.bulletholder.getChildAt(i);
    if (hitTestObject(bulletTarget)) {
     core.bulletholder.getChildAt(i).removeListeners();
     core.bulletholder.removeChild(bulletTarget);

     removeEventListener(Event.ENTER_FRAME, loop);
     core.removeChild(this);
    }
   }

  }
  
  public function removeListeners():void {
   removeEventListener(Event.ENTER_FRAME, loop);
  }
 }
}


So ideally I’d like to have the function onstart execute every 5 seconds but I’m out of ideas. Thanks in advance for any suggestions!