0

我有五个按钮,其中包含五首歌曲。然后我有一个播放按钮和停止按钮。现在,当我单击一首歌曲按钮,然后单击播放按钮时,应该播放相应的歌曲。当我按下停止按钮时,歌曲应该停止。我再次选择不同的歌曲并单击播放按钮,应该播放指定的歌曲。我正在使用下面给出的代码,但我无法获得输出。请帮帮我……!!

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

    }

}
4

1 回答 1

0

url仅仅改变以下代码是不够的,您需要一个new audio()语句来实际加载该声音并播放它。正确的方法是,如果您audio使用所有 5 个不同的 URL 初始化所有 5 个对象,它们都将处于停止状态,然后显示它们并单击它们的按钮。

于 2013-03-26T10:41:41.777 回答