[英]long run error after calling the javascript method from the action script
我正在尝试使用ExternalInterface从动作脚本中调用javascript方法。 这是动作脚本中的代码
private function onKickEvent(e:LogoutEvent):void{
ExternalInterface.call("LoginFound","message");
return;
}
这是我的javascript mwthod
function LoginFound(message){
alert(message);
anotherInstanceExists=true;
}
一切工作正常,但是唯一的事情是,在大约20秒后对javascript中显示的警报框进行操作时,Flash Player抛出异常,该脚本的运行时间比预期时间长15秒。
我如何避免这种情况?
解决此问题的最佳方法是在警报行中的JavaScript内添加setTimeout。 它看起来应该像这样:
setTimeout(function(){ alert(message) }, 1);
通过这种方式,执行不会因为警报而停止。
当您从actionscript
调用js
函数时,该函数必须工作并且返回值的时间不得超过15 sec
。 Javascript
在单线程中运行 ,当您调用LoginFound
函数时, alert
停止线程上的进一步执行。
function LoginFound(message){
alert('something');
//Nothing will be executed unless `alert` window will be closed
}
但是,您可以使用try/catch
在Actionsript
处理这种情况(执行时间超过15秒):
private function onKickEvent(e:LogoutEvent):void{
try{
ExternalInterface.call("LoginFound","message");
}catch(e:Error){
//Do something
}
}
我认为您的onKickEvent
经常被调用
这样就可以定期调用javascript。 最终浏览器超时事件
发生。 它总是在递归函数中发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.