How to determine if a Flex application will lose an application

As an answer to this question: Developing an online exam application, how can I prevent fraudsters?

Can I detect when a Flex application loses focus? that is, if the user clicked on another application or opened a browser tab?

I read this: Detecting when a Flex application loses focus , but it was not very clear ...

+4
source share
4 answers

The key part of the code on this link is

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

Sending a flash player activates and deactivates events when focus enters and leaves the player. All you have to do is create an audition for them and react accordingly.

A more striking example of how to use to activate and deactivate events can be seen on blog.flexaxamples.com .

In addition, it appears that events are activated and deactivated in some browsers. Colin Moock has more info on this here.

+5
source

You can add a handler for activation in the main tag of the application. This detects when the flex application is suitable for focusing. For instance:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" activate="activateHandler(event);" deactivate="deactivateHandler(event);">

+1
source

This will work to detect when a Flex window loses focus, but to determine when a window regains focus without actually clicking on the flex application, an update in the HTML shell is required, right? Sort of:

 <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 executed as soon as I return to the flex application window. When I look at the source, the code is there. Does anyone know why?

Thanks Annie

0
source

In Flex 4.6, this command works systemManager.stage.addEventListener (event .DEACTIVATE, deactivate), but make sure that the wmode flash application is set to "window" (the default). When wmode was transparent, the event did not come across. You install wmode in the built-in html where you put your flash application. Example:

 <object classid="clsid:D27WEE-A16D-21cf-90F2-422253540410" width="100%" height="100%" id="MyApp" name="MyApp" align="middle"> <param name="movie" value="MyApp.swf?v=1.00.008" /> <param name="wmode" value="transparent"> <----- take out this 

...

0
source

Source: https://habr.com/ru/post/1276570/


All Articles