弹性按钮乘以点击次数

时间:2013-05-19 22:24:31

标签: flex button click

在我的项目(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);}

PlayCode:

   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++;
        }

Playstart功能:

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

1 个答案:

答案 0 :(得分:1)

这里的问题是每次按下按钮时调用addEventListener(Event.ENTER_FRAME,displayProgressInSec)但从不删除它。每次添加侦听器时,它都会累积,并且所有响应都会响应输入帧事件。