I started to suggest the same thing about using the javaScript method. But
I haven't tested it yet and I am curious to know will that method in the swf
that is called by the js fire quickly enough before the actual session
closes?
Take for instance you want to save user preferences to a local shared object
onClose. I am just guessing here, but I would think that the browser's
internal close mechanics would not wait around for the js, and subsequent
swf methods to do their business.
Has this been tested and confirmed by anyone?
On 2/16/07, Evan Bellinger <[EMAIL PROTECTED]> wrote:
Julien,
Not sure what you're really trying to do here. A bit more of a
description would be useful. I'll take a shot anyway.
I'm going to guess that you've got your application running in a
browser. As such, you've got a couple options.
First, and most obviously, you could have a "close" button in your
application which logs you out or ends the chat or whatever. Just
leech off of that event, and away you go.
Secondly, if you want to try to capture the closing of the browser
window, there's a javascript event that you'll want to capture and tie
it to a method in your application through the ExternalInterface.
Here's a quick snippet of something similar to what I use:
[Javascript]
window.onbeforeunload = browserClosing;
function browserClosing(event_)
{
getSWF("MyTestApp").theBrowserIsClosing();
}
// Gets a reference to the specified SWF file by checking which browser is
// being used and using the appropriate JavaScript.
function getSWF(movieName)
{
if (navigator.appName.indexOf("Microsoft") != -1)
return window[movieName];
else
return document[movieName];
}
[/Javascript]
[MXML]
<mx:Application ... creationComplete="load();">
<Script><![CDATA[
private function load():void
{
if(ExternalInterface.available)
{
try
{
ExternalInterface.addCallback("theBrowserIsClosing",
theBrowserIsClosingHandler);
}
catch(e:Error){}
}
}
private function theBrowserIsClosingHandler():String
{
//Do whatever needs to be done here.
}
]]></Script>
</mx:Application>
[/MXML]
When your user hits the browser's close button, the onbeforeunload
event will fire calling the javascript method 'browserClose' which in
turn will call the 'theBrowserIsClosing' method in your application.
Hope that gets you pointed in the right direction. If not, be a bit
more specific about what you're trying to do.
Evan
--- In [email protected], "julien castelain" <[EMAIL PROTECTED]>
wrote:
>
> Hi all,
>
> I was wondering if there was a way to be notified when the user
"leaves" or
> "quits" the application using AS3.
>
> Thanks.
>
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
--
justin w. opitz
617.771.6639
jwopitz(at)gmail.com