变量currentIndex是全局声明的,并用一个特定的值“0”初始化。如何保存每次调用函数时递增的currentIndex的值?在给定的代码中,每次调用该函数时,都会重新初始化该值。如何增加函数内的全局变量?
function nextSong(e:Event):void { sc.stop(); currentIndex = currentIndex + 1; var nextSongFunc:URLRequest = new URLRequest(songlist[currentIndex].file); var nextTitle:Sound = new Sound(); nextTitle.load(nextSongFunc); currentSound = nextTitle; sc = currentSound.play(); sc.addEventListener(Event.SOUND_COMPLETE, nextSong); } NextBtn.addEventListener(MouseEvent.CLICK, nextSong);