Adobe Flash

Flash/Flex监听浏览器的关闭事件

如果想用Flash/Flex监听浏览器的关闭事件,

可以通过JavaScript的window.onbeforeunload事件进行监听
然后JS调用Flash中的函数。
在swf所在页面的JavaScript中添加如下代码
JS中代码:(这里设定swf文件名为TestFlash)
window.onbeforeunload = onbeforeunloadHandler; //添加响应函数
function onbeforeunloadHandler()
{
var swfRef = document.TestFlash|| window.TestFlash; //获取swf的引用
if ( swfRef )  {
warning = swfRef.windowCloseHandler(); // 调用Flash中的windowCloseHandler函数
return “Are you sure to close this page?”;
}
}
AS中代码:(在程序初始化的函数中添加,例如Flex的creationComplete事件中)
if(flash.external.ExternalInterface.available){ flash.external.ExternalInterface.addCallback(‘windowCloseHandler’,externalWindowCloseHandler);
//使用ExternalInterface向JS中添加调用函数
}

/*

* 告诉服务器,该flash已经被关闭

*/
protected function externalWindowCloseHandler():void{

//use HttpService in Flex
var http:HTTPService = new HTTPService();
http.url = ‘http://localhost/testphp/index.php?from=flexcloseByHTTPService’;
http.send();
//use URLLoader in AS3
var request:URLRequest = new URLRequest(‘http://localhost/testphp/index.php?                from=flexcloseByUrlLoader’);
var urlLoader:URLLoader = new URLLoader();
urlLoader.load(request);
}
Flex中可以在FlashBuilder的HTML模板上添加JS代码

修改html-template中的index.template.html文件

在其中添加JS代码:

window.onbeforeunload = onbeforeunloadHandler; //添加响应函数
function onbeforeunloadHandler()
{
var swfRef = document.${application}|| window.${application};   //获取swf的引用
if ( swfRef )  {
warning = swfRef.windowCloseHandler();    // 调用Flash中的windowCloseHandler函数
return “Are you sure to close this page?”;
}
}
在AS中直接注入JS代码

如果不想更改HTML文件,也可以在AS中直接书写JS代码,注入到HTML文档中

if(flash.external.ExternalInterface.available){
var jsStr:String;

jsStr =
‘eval(\’window.onbeforeunload = onbeforeunloadHandler;’ +
‘function onbeforeunloadHandler(){‘ +
‘var swfRef = document.’+FlexGlobals.topLevelApplication.className+’ || window.’+FlexGlobals.topLevelApplication.className+’;’ +
‘swfRef.windowCloseHandler();’ +
‘return “Are you sure to close this page?”;’ +
‘}\’)';
flash.external.ExternalInterface.call(jsStr);

flash.external.ExternalInterface.addCallback(‘windowCloseHandler’,externalWindowCloseHandler);

}
移除该监听

只要设置window.onbeforeunload=null即可

AS中可以这样写

flash.external.ExternalInterface.call(‘eval(\’window.onbeforeunload = null\’)');

flash.external.ExternalInterface.call(‘eval(\’location.reload();\’)');        //再执行刷新浏览器的命令

源文件 :TestFlex.zip

Flash Builder4, Flex4, ColdFusion Builder今天正式发布

个人使用了一下Flash Builder以及Flex4,感觉的确是一个很大的改进。下面是adobe社区的发布信息

Dear community,

We are thrilled to announce that as of today (3/22) final GA releases of Flash Builder 4, the Flex 4 framework, and the new ColdFusion Builder are out. Each of you have played a key role in helping Adobe spread the details about the earlier beta releases and we are looking forward to working with you over the coming weeks to get the news out about the final releases. In the coming weeks, members of Adobe’s product and evangelist teams will be visiting many of your user groups to help your members further explore the many new features and what can be built with them.

Thank you SO much for all that you do to help us build and sustain the awesome community around these great products!

Sincerely,

Dave Gruber, Group Product Marketing Manager
Flash Platform Tools

Check out these online resources to learn more:

· Read Andrew Shorten’s FlexTeam blog post

· AdobeTV: Learn what developers like about Flash Builder in this video from Flash Camp Boston from March 19th

· AdobeTV: David Wadhwani, VP and GM of Adobe’s Platform BU introduces new Flash Platform products

· Test drive Flex 4 Check out the new Flex Test Drive: Build an application in an hour and learn about Flex 4 using this new guided, video tutorial

· Flex-in-a-week free video training new for Flex 4

· Get Flash Builder 4 (remember to uninstall any FB4 beta SW first)

· Get ColdFusion Builder

· Video: ColdFusion Builder Feature Tour