我有五个按钮,其中包含五首歌曲。然后我有一个播放按钮和停止按钮。现在当我点击一个歌曲按钮然后点击播放按钮时,相应的歌曲应该播放。我按下停止按钮,歌曲应该停止。再次选择不同的歌曲并点击播放按钮,指定的歌曲应该播放。我使用下面给出的代码,但我无法得到输出。请帮帮我...... !!
sng1.addEventListener(MouseEvent.CLICK, mclick);
sng2.addEventListener(MouseEvent.CLICK, mclick);
sng3.addEventListener(MouseEvent.CLICK, mclick);
sng4.addEventListener(MouseEvent.CLICK, mclick);
sng5.addEventListener(MouseEvent.CLICK, mclick);
var url:String;
function mclick(e:MouseEvent)
{
//private var url:String = "FIFA Theme song.mp3";
if(e.currentTarget.name == "sng1")
{
url="Ippadi Mazhai.mp3";
}
else if (e.currentTarget.name == "sng2")
{
url = "06 Gore Gore.mp3";
}
else if (e.currentTarget.name == "sng3")
{
url = "FIFA Theme song.mp3";
}
else if (e.currentTarget.name == "sng4")
{
url = "babe.mp3";
}
else if (e.currentTarget.name == "sng5")
{
url = "fast_and_furious_5.mp3";
}
}
public class audio extends Sprite{
private var song:SoundChannel;
private var soundFactory:Sound;
public function audio() {
var request:URLRequest = new URLRequest(url);
soundFactory = new Sound();
soundFactory.addEventListener(Event.COMPLETE, completeHandler);
soundFactory.addEventListener(Event.ID3, id3Handler);
soundFactory.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
soundFactory.load(request);
song = soundFactory.play();
plybtn.addEventListener(MouseEvent.CLICK, plClick);
stpbtn.addEventListener(MouseEvent.CLICK, stpClick);
}
private function completeHandler(event:Event):void {
trace("completeHandler: " + event);
}
private function id3Handler(event:Event):void {
trace("id3Handler: " + event);
}
private function ioErrorHandler(event:Event):void {
trace("ioErrorHandler: " + event);
}
private function progressHandler(event:ProgressEvent):void {
trace("progressHandler: " + event);
}
private function plClick(evt:MouseEvent)
{
song = soundFactory.play();
}
private function stpClick(evt:MouseEvent)
{
song.stop();
}
}
}
答案 0 :(得分:0)
仅仅更改url
以使以下代码正常工作是不够的,您需要一个new audio()
语句来实际加载该声音并播放它。一种正确的方法是,如果您使用所有5个不同的URL初始化所有5个audio
个对象,它们都将处于停止状态,然后显示它们并单击它们的按钮。