Confirmation of browser close eventCalculoso Feb 19, 2010 10:49 AM
Hello,
In my application, I have a function "myCloseFunction" which looks something like this:
public function myCloseFunction
{
Alert.show("This is an alert.");
trace("myCloseFunction called");
}
This is only called upon closing the browser (set up using ExternalInterface.addCallback and window.onbeforeunload)
The strange thing is, no alert ever pops up BUT the trace does show. I have (of course) imported the alerts library (and used alerts elsewhere successfully in the application). Has anyone ever experienced it or does anyone know of a fix?
I will post my Javascript and .mxml file if needed, though I doubt it is.
Thanks in advance for your help!
1. Re: Confirmation of browser close eventFlex harUI
Feb 19, 2010 2:19 PM (in response to Calculoso)
I don't think you can block in Actionscript, and Alert doesn't block anyway.
I don't think there is a way to use AS to interact during that event.
2. Re: Confirmation of browser close eventCalculoso Feb 20, 2010 1:28 PM (in response to Flex harUI)
Hmm, that is certainly useful information. Is there anyway to do this in JS? I
assume that it is prevented do to potential abuses from developers P.O.V. in terms of spamming and other similar issues.
Anyone have any ideas about handling browser close (y/n) choice from user? It "should" be part of the browser ideally, but I'd like to put it in my application if necessary.
Thanks for your help.
3. Re: Confirmation of browser close eventxingwen May 3, 2010 3:09 PM (in response to Calculoso)
hi,
Frastructed with the window close example using ExternalInterface.addCallback provided by Adove not working. Any help would truly appreciated. here is what i've found:
1. when tested, it passes data from html to Flex if I use onchange="callApp();" of the <Input> tag by typing something to invoke onchange event;
2. if I choose to use window.onbeforeunload = callApp(); at the JavaScript section to detect window closing event, it does detect window is closing, but it won't pass the data ("Window Closing") to Flex.
Thank you very much for any help.
In Html:
<html><head>
<title>wrapper/AddCallbackWrapper.html</title>
<SCRIPT LANGUAGE="html/JavaScript">
function callApp() {
window.document.title = document.getElementById("newTitle").value;
mySwf.myFlexFunction("Window Closing");
}
//window.onbeforeunload = callApp();
</SCRIPT>
</head>
<body scroll='no'>
<h1>AddCallback Wrapper</h1>
Enter a new title: <input type="text" size="30" id="newTitle" onchange="call='testWrapper.swf'/>
<param name='flashVars' value=''/>
<embed name='mySwf' src='testWrapper.swf' pluginspage='' height='100%' width='100%' flashVars=''/>
</object>
</td>
</tr>
</table></body></html>
In Flex:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:
<mx:Script>
<![CDATA[
import flash.external.*;
import mx.rpc.events.ResultEvent;
import flash.events.Event;
import mx.rpc.events.FaultEvent;
import mx.controls.Alert;
public function initApp():void {
ExternalInterface.addCallback("myFlexFunction",myFunc);
}
public function myFunc(s:String):void {
Alert.show(s);
}
]]>
</mx:Script>
<mx:Label
</mx:Application>
4. Re: Confirmation of browser close eventMatt Le Fevre May 4, 2010 1:41 AM (in response to xingwen)
quick and easy way how to accomplish this