Timer HELP

like i said bfore i am making a totally scripted random animation thing and need some help. I am trying to use a timer so that every 4 seconds it will attach movieclips, but dont know how to script it. cud som1 help me. this is what i got so far.

 
onEnterFrame = function() {
 //random number generator
 rand = Math.random()*20;
 //how many movie clips should be on the screen at once
 obstacles = 2;
 curobs = 0;
 time = Math.floor(getTimer()/1000);
 if(time == 4) {
  //if rand is greater than or equal to 16 load rail
  if(rand >= 16) {
   _root.attachMovie("rail", "rail" + rand, rand)
  }
  //if rand is between 5 and ten load gap
  if( (rand > 5) and (rand < 7)) {
   _root.attachMovie("gap", "gap" + rand, rand)
  }
  //if rand is less than or equal to 5 load wall
  if(rand <= 5) {
   _root.attachMovie("wall", "wall" + rand, rand)
  }
 }
}