当事件到达 startLoad 方法时禁用从 e.target 获得的按钮将改善代码的行为。然后区分每个 swf 的 onCompleteHandler 方法将使您有机会重新启用相应的按钮。
由于我对你的按钮类一无所知,所以我称它为 YourButtonClass,我将编写 disable(); 和启用();在下面的示例中,用于禁用和启用按钮的方法。请用适当的正确类名方法或属性设置替换它们。同时检查 e.target 类和按钮将避免不必要的悲剧。
function startLoad(e:MouseEvent){
var mLoader:Loader; // we havent seen the river, lets not inflate our boat.
var mRequest:URLRequest;
if(!(e.target is YourButtonClass)) return; // no nightmares..
if((e.target != btnOne)&&(e.target != btnTwo))return; // no nightmares..
YourButtonClass(e.target).disable(); // disable the button here
mLoader = new Loader(); // river! inflate the boat :)
if (e.target == btnOne){
mRequest = new URLRequest("appOne.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteAppOne);
}
else { // we are sure it is btnTwo if not btnOne now...
mRequest = new URLRequest("appTwo.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteAppTwo);
}
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}
// this method is for enabling btnOne
protected function onCompleteAppOne(Event: e){
btnOne.enable();
commonCompleteOperations(e);// if you have other operations post processing
}
// this method is for enabling btnTwo
protected function onCompleteAppTwo(Event: e){
btnTwo.enable();
commonCompleteOperations(e);// if you have other operations post processing
}
// this method is for on complete common operations if you have.
protected function commonCompleteOperations(Event e){
// do some processing here, for instance remove event listener check for
// application domain etc...
}
作为预防措施,我会监听安全错误和 io 错误事件。两个错误事件都可以由每个按钮/文件的单个处理程序方法处理。