flex button multiply clicks -
in project (mp3 player) when click button 'play' starts amd plays normal, when click button 'next song' multiplys clicks,(2 clicks multiply 2 times, 3 clicks 3 times...) , it's starting 2 or 3 or more songs in background. why it's multiply button clicks? can me?
buttons:
<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="=>>" click="nastepnybtn_clickhandler(event)"/>
actions:
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 odegrania!"); } test++; }
playstart function:
private function play(pos:number=0):void{ playing=true; kanal=muzyka.play(pos,trans); refresh(); addeventlistener(event.enter_frame, displayprogressinsec); }
the problem here calling addeventlistener(event.enter_frame, displayprogressinsec) everytime hit button never removing it. everytime add listener, accumulates , responds enter-frame event.
Comments
Post a Comment