<p>As a follow up to this question: <a href="https://stackoverflow.com/questions/46873/developing-a-online-exam-application-how-do-i-prevent-cheaters">Developing a online exam application, how do I prevent cheaters?</a></p>

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

<p>I read this: <a href="http://blog.flexmonkeypatches.com/2007/12/07/detecting-when-a-flex-application-loses-focus/" rel="nofollow noreferrer">Detecting when a Flex application loses focus</a> but was not very clear...</p>

[{'answer_id': 47161, 'author': 'Raleigh Buckner', 'author_id': 1153, 'author_profile': 'https://Stackoverflow.com/users/1153', 'pm_score': 4, 'selected': True, 'text': '<p>The key part of the code at that link is the </p>\n\n<pre><code>systemManager.stage.addEventListener(Event.DEACTIVATE,deactivate);\n</code></pre>\n\n<p>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.</p>\n\n<p>A more clear example of how to use to the activate and deactivate events can be seen at <a href="http://blog.flexexamples.com/2008/02/29/determining-if-a-flex-application-has-focus-using-the-activate-and-deactivate-events/" rel="noreferrer">blog.flexaxamples.com</a>. </p>\n\n<p>Also, it looks like the activate and deactivate events have trouble in some browsers. <a href="http://www.moock.org/blog/archives/000252.html" rel="noreferrer">Colin Moock has more info on that here.</a></p>\n'}, {'answer_id': 158463, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>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:</p>\n\n<pre><code>&lt;script language="JavaScript" type="text/javascript"&gt;\n&lt;!--\n// -----------------------------------------------------------------------------\n// Globals\n// Major version of Flash required\nvar requiredMajorVersion = ${version_major};\n// Minor version of Flash required\nvar requiredMinorVersion = ${version_minor};\n// Minor version of Flash required\nvar requiredRevision = ${version_revision};\n// -----------------------------------------------------------------------------\n// --&gt;\n\n\n    function onAppFocusIn()\n    {\n        ${application}.onAppFocusIn();\n        alert("onAppFocusIn");\n    }\n\n&lt;/script&gt;\n&lt;body scroll="no" onFocus="onAppFocusIn()"&gt;\n</code></pre>\n\n<p>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??</p>\n\n<p>Thanks,\nAnnie</p>\n'}, {'answer_id': 6071245, 'author': 'Preeyanka', 'author_id': 762650, 'author_profile': 'https://Stackoverflow.com/users/762650', 'pm_score': 1, 'selected': False, 'text': '<p>You can add a handler for activate in the main application tag. This detects whenever the flex application comes to focus. \nEg:  </p>\n\n<p><code>&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"\n        layout="vertical"\n        verticalAlign="middle"\n        backgroundColor="white"\n        activate="activateHandler(event);"\n        deactivate="deactivateHandler(event);"&gt;</code></p>\n'}, {'answer_id': 20466605, 'author': 'Patrick', 'author_id': 2495697, 'author_profile': 'https://Stackoverflow.com/users/2495697', 'pm_score': 0, 'selected': False, 'text': '<p>In Flex 4.6, this command works  systemManager.stage.addEventListener(Event.DEACTIVATE, deactivate)\nbut make sure the flash app wmode is set to window (default). When the wmode was transparent, the event didn\'t get caught. You set the wmode in the embedded html where you put your flash app. example:</p>\n\n<pre><code>&lt;object classid="clsid:D27WEE-A16D-21cf-90F2-422253540410" width="100%" height="100%"\nid="MyApp" name="MyApp" align="middle"&gt;\n&lt;param name="movie" value="MyApp.swf?v=1.00.008" /&gt;\n&lt;param name="wmode" value="transparent"&gt;      &lt;----- take out this\n</code></pre>\n\n<p>...</p>\n'}]
['https://Stackoverflow.com/questions/46915', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1638/']