-
StackOverflow 文档
-
ActionScript 3 教程
-
使用声音
-
停止播放声音
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.Event;
var snd:Sound; = new Sound();
var sndChannel:SoundChannel
var sndTimer:Timer;
snd.addEventListener(Event.COMPLETE, soundLoaded);
snd.load(new URLRequest("soundFile.mp3")); //load after adding the complete event
function soundLoaded(e:Event):void
{
sndChannel = snd.play();
//Create a timer to wait 1 second
sndTimer = new Timer(1000, 1);
sndTimer.addEventListener(TimerEvent.TIMER, stopSound, false, 0, true);
sndTimer.start();
}
function stopSound(e:Event = null):void {
sndChannel.stop(); //Stop the sound
}