所以我有一个主SWF作为主菜单启动其他SWF并启动正常,但当其他应用程序运行时,您仍然可以单击主菜单上的按钮...
function startLoad(e:MouseEvent){
var mLoader:Loader = new Loader();
var mRequest:URLRequest;
if (e.target == btnOne){
mRequest = new URLRequest("appOne.swf");
}
else if (e.target == btnTwo){
mRequest = new URLRequest("appTwo.swf");
}
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}
我可以禁用主菜单按钮,但是到目前为止我还没有找到触发主菜单重新启用它们的方法。
答案 0 :(得分:1)
当事件到达startLoad方法时,禁用从e.target获得的按钮将改善代码的行为。然后区分每个swf的onCompleteHandler方法将使您有机会重新启用相应的按钮。
由于我对你的按钮类一无所知,所以我称之为YourButtonClass,我会写disable();和enable();在下面的示例中,用于禁用和启用按钮的方法。请使用适当的正确类名方法或属性设置替换它们。同时检查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...
}
作为预防措施,我会听安全错误和错误事件。每个按钮/文件都可以通过单个处理程序方法处理这两个错误事件。