0

所以我有一个主 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);
}

我可以禁用主菜单按钮并且可以工作,但到目前为止我还没有找到触发主菜单以重新启用它们的方法。

4

1 回答 1

1

当事件到达 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 错误事件。两个错误事件都可以由每个按钮/文件的单个处理程序方法处理。

于 2013-02-21T22:17:26.780 回答