Loading sound- and playing it more than once
Filed under Lab Work, Programming | Tags:Actionscript 3,Flash,Sound
One thing i am learning is to always read every possible event in the flash docs. DisplayObects, Sound, Components, etc all have seeming unique events that you would not necessarily remember until years of versed coding. Today’s headache was why the sound would load fine, but play once. Turns out that, while not its own “SoundEvent”, there is an Event dedicated to sound being played in its complete state…ie , to its finishing note. Then the sound will dispatch a new Event.SOUND_COMPLETE, and it is at that moment, that we the mighty programmers have to listen and respond. A recursive “play it again , Flash” function can be used, and in the case, the same function that started us off:
var urlr:URLRequest= new URLRequest() urlr.url="testloop.mp3" var sd:Sound= new Sound(urlr); function init() { var sc:SoundChannel= sd.play() sc.addEventListener(Event.SOUND_COMPLETE,reloop); } function reloop(e:Event) { sd.play(); init() } init()