0

在我的项目(mp3 播放器)中,当我单击“播放”按钮时,它开始正常播放,但是当我单击“下一首歌曲”按钮时,它会增加我的点击次数,(2 次点击乘以 2 次,3 次点击 3 次......)和它在背景中开始播放 2 首或 3 首或更多歌曲。为什么它会增加我的按钮点击次数?有人可以帮助我吗?

纽扣:

<s:Button id="PlayBtn" x="97" y="14" width="79" height="24" label="Play" 
          click="playButton_clickHandler(event)" enabled="true"/>
<s:Button id="nastepnyBtn" x="354" y="14" width="79" height="24" label="=&gt;&gt;" click="nastepnyBtn_clickHandler(event)"/>

行动:

  protected function playButton_clickHandler(event:MouseEvent):void {Odtwarzaj();}

  protected function nastepnyBtn_clickHandler(event:MouseEvent):void {Odtwarzaj(1);}

播放代码:

   function Odtwarzaj(tryb:Number=0):void{
            var wybrany:Object = dataGridId.selectedItem;

            if(wybrany!=null){
                switch(tryb){
                    case 0:
                        if(playing)
                        stop();

                        WybranyKawalek=dataGridId.selectedIndex;
                        break;
                    case 1:
                        if(!Normalnie.selected){
                            Alert.show("losuje");
                        }else
                        {
                            if(WybranyKawalek==tablica.length-1){
                                WybranyKawalek=0;
                            }else
                            {
                                WybranyKawalek=WybranyKawalek+1;
                            }

                        }
                        stop();
                        //playing=false;
                        break;
                    case 2:
                        if(!Normalnie.selected){
                            Alert.show("losuje");


                        }else
                        {
                            if(WybranyKawalek==0){
                                WybranyKawalek=tablica.length-1;
                            }
                            else{   

                                WybranyKawalek=WybranyKawalek-1;
                            }
                        }
                        stop();
                        //playing=false;
                        break;

                    }


                    Alert.show("test="+test+" tryb="+tryb+" wybrany:"+WybranyKawalek+" t.l="+tablica.length+" dg.si="+dataGridId.selectedIndex);


                    playingLable.text=tablica.getItemAt(WybranyKawalek).artysta+" - "+tablica.getItemAt(WybranyKawalek).tytul;
                    file = new File(tablica.getItemAt(WybranyKawalek).URL_PLIKU);

                    if(!playing){
                        muzyka=new Sound();
                        muzyka.addEventListener(IOErrorEvent.IO_ERROR, errorHandlerMusic);
                        muzyka.addEventListener(Event.COMPLETE, loadCompleteMusic);
                        muzyka.load(new URLRequest(file.url));//, context

                        }


            }else{
                Alert.show("Zaznacz plik do odegrania!");
            }

            test++;
        }

播放开始功能:

      private function play(pos:Number=0):void{
            playing=true;
            kanal=muzyka.play(pos,trans);
            refresh();
            addEventListener(Event.ENTER_FRAME, displayProgressInSec);
        }
4

1 回答 1

1

这里的问题是每次点击按钮时都调用 addEventListener(Event.ENTER_FRAME, displayProgressInSec) 但从不删除它。每次添加侦听器时,它都会累积并全部响应 enter-frame 事件。

于 2013-05-20T19:05:19.023 回答