Random sound not working

Found this code on a thread and thought I could use it for my game (think it’s by Faro…sorry otherwsie to whoever created it)


  var ranSound = new Sound(this)
  var theKey = new Object();
  theKey.onKeyDown = function() {
  		if (Key.isDown(Key.SPACE)) {
 			 _level0.ranSound.attachSound("s"+Math.round(Math.random()*5))
  		}
  		ranSound.start()
  };
  Key.addListener(theKey);

Where I have changed the Linkage to s0, s1, s2, s3 . Sound does play but when the Space Bar is pressed another sound plays **ontop. **Any idea how this can be avoided?

Cheers anyone can help!

Y