0

青蛙

我正在开发一个名为 Frog 的 Flash 游戏,目前我的声音代码似乎有点多,我想简化它,但看不出如何。任何帮助,将不胜感激。

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();
4

1 回答 1

0

声音对象的播放方法有第二个参数,用于循环次数:

musicS.play(0, int.MAX_VALUE);

int.MAX_VALUE 对于您的应用来说应该是足够的循环。

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

于 2012-04-26T23:01:07.757 回答