我有一個AS3函數加載和音頻文件,然後播放它。我有第一個音頻文件工作的預加載器 - 現在我需要在第二個音頻文件啓動之前運行預加載功能。Actionscript 3 - 從另一個函數內部調用onLoadProgress函數
myMusic.addEventListener(ProgressEvent.PROGRESS, onLoadProgress2, false,0, true);
myMusic.addEventListener(Event.COMPLETE, playMusicNow, false, 0,true);
myMusic.load(soundFile, myContext); //This code works
這裏是劇中代碼:
//此代碼不能正常工作
function receiveText1(value:String):void {
channel.stop();
channel2.stop();
songPosition = 0;
soundFile2 = new URLRequest(jsVariableValue1);
myMusic2= new Sound(); //Intstantation
myMusic2.load(soundFile2, myContext);
//need to run preloader here
soundFile2exist = null;
}
這是我的事件偵聽器和預加載:
myMusic2.addEventListener(ProgressEvent.PROGRESS, onLoadProgress, false,0, true);
myMusic2.addEventListener(Event.COMPLETE, playMusicNow, false, 0,true);
function onLoadProgress(evt:ProgressEvent):void {
progBar.alpha = .70;
prcLoaded.alpha = .70;
var pcent:Number=evt.bytesLoaded/evt.bytesTotal*100;
prcLoaded.text =int(pcent)+"%";
progBar.width = 90 * (evt.bytesLoaded/evt.bytesTotal);
}
我想我可致電
onLoadProgress(evt:ProgressEvent);
從函數中,但我發現了一個錯誤
1084: Syntax error: expecting rightparen before colon.
這是編譯錯誤還是運行時錯誤? –
你不能調用一個聲明參數類型的函數。考慮通過監聽器函數和代碼中的另一個地方創建共享功能。 – papachan
那麼有可能調用相同的函數嗎?或者我應該把我的事件監聽器放在recieveText1函數中? – user547794