我有一个 Flex 客户端应用程序。当用户关闭浏览器时,我需要一个清理功能才能在 Flex 中运行。我在网上找到了以下解决方案,但它只对我有用。我该如何解决?提前感谢您的任何回复!
症状
CustomEvent
触发,但未执行。
>> EventHandlerCustomEvent.SEND_EVENTS
由 Mate EventMap 定义。处理程序所做的只是调用一个HTTPServiceInvoker
. 在调试控制台中,我可以看到处理程序和 HTTPServiceInvoker 被触发,但既没有调用 theresultHandlers
也没有faultHandlers
调用 the 。我知道这个事件处理程序没有问题,因为当我CustomEvent.SEND_EVENTS
在按钮单击处理程序中调度它时,它的行为完全符合我的预期)- 浏览器似乎在关闭之前等待清理功能完成。(所有痕迹都是在浏览器关闭之前打印出来的)
代码
我将以下内容添加到 index.template.html
window.onbeforeunload = clean_up;
function clean_up()
{
var flex = document.${application} || window.${application};
flex.cleanUp();
}
并在应用程序 MXML 文件中使用了以下内容
import flash.external.ExternalInterface;
public function init():void {
ExternalInterface.addCallback("cleanUp",cleanUp);
}
public function cleanUp():void {
var newEvent:CustomEvent = new CustomEvent(CustomEvent.SEND_EVENTS);
newEvent.requestObj = myFormModel;
dispatchEvent(newEvent);
// for testing purposes
// to see whether the browser waits for Flex cleanup to finish before closing down
var i:int;
for (i=0; i<10000; i++){
trace(i);
}
}
我的设置
- 弹性生成器 3
- Mate MVC 框架 (Mate_08_9.swc)
- 闪存播放器 10