變量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);