views:

1311

answers:

2

As a follow up to this question: http://stackoverflow.com/questions/46873/developing-a-online-exam-application-how-do-i-prevent-cheaters

Can I detect when Flex application looses its focus? that is if a user has clicked onto another application or opened a browser tab?

I read this: http://blog.flexmonkeypatches.com/2007/12/07/detecting-when-a-flex-application-loses-focus/ but was not very clear...

+3  A: 

The key part of the code at that link is the

systemManager.stage.addEventListener(Event.DEACTIVATE,deactivate);

The Flash player send outs activate and deactivate events when the focus enters and leaves the player. All you need to do is create a listenr for them and react appropriately.

A more clear example of how to use to the activate and deactivate events can be seen at blog.flexaxamples.com.

Also, it looks like the activate and deactivate events have trouble in some browsers. Colin Moock has more info on that here.

81bronco
won't work if wmode is transparent or opaque
jedierikb
A: 

This will work to detect when the Flex windows loses focus, but to detect when the window regains focus without having to actually click on the flex app requires an update in the HTML wrapper, correct? Something like:

<script language="JavaScript" type="text/javascript">
<!--
// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = ${version_major};
// Minor version of Flash required
var requiredMinorVersion = ${version_minor};
// Minor version of Flash required
var requiredRevision = ${version_revision};
// -----------------------------------------------------------------------------
// -->


    function onAppFocusIn()
    {
     ${application}.onAppFocusIn();
     alert("onAppFocusIn");
    }

</script>
<body scroll="no" onFocus="onAppFocusIn()">

I am trying to implement this but the onAppFocusIn() function is not executing once I move back to the flex app window. When I view the source, the code is there. Does anyone know why??

Thanks, Annie