0
votes

Frog

I'm developing a flash game called Frog, at the moment my code for sound seems a bit much, I'd like to simplify it but can't see how. Any help would be appreciated.

var musicSC:SoundChannel = new SoundChannel();
var musicST:SoundTransform = new SoundTransform();
var musicS:Sound = new Sound();
var musicURLR:URLRequest = new URLRequest('audio/music.mp3');
var flySC:SoundChannel = new SoundChannel();
var flyST:SoundTransform = new SoundTransform();
var flyS:Sound = new Sound();
var flyURLR:URLRequest = new URLRequest('audio/fly.mp3');
var frogSC:SoundChannel = new SoundChannel();
var frogST:SoundTransform = new SoundTransform();
var frogS:Sound = new Sound();
var frogURLR:URLRequest = new URLRequest('audio/frog.mp3');

function loopMusic():void {
    musicSC = musicS.play();
    musicSC.addEventListener(Event.SOUND_COMPLETE, loopMusic);
}
function loopFrog():void {
    frogSC = frogS.play();
    frogSC.addEventListener(Event.SOUND_COMPLETE, loopFrog);
}
function playFly():void {
    flySC = flyS.play();
}

musicS.load(musicURLR);
flyS.load(flyURLR);
frogS.load(frogURLR);
loopMusic();
loopFrog();
1

1 Answers

0
votes

The play method of the sound object has a second parameter for the number of loops:

musicS.play(0, int.MAX_VALUE);

int.MAX_VALUE should be enough loops for your app.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html