我有一个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