Flex:检测用户空闲?

发布于 2024-08-20 11:43:23 字数 88 浏览 14 评论 0原文

如何判断用户何时在我的 Flex 应用程序上闲置了 5 分钟?

当我说“空闲”时,我的意思是用户根本没有与应用程序交互。

谢谢!!

How can I tell when a user has been idle for say 5 minutes on my Flex app?

When I say "idle" I mean the user has not interacted with the application at all.

Thanks!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

尸血腥色 2024-08-27 11:43:23

另请参阅 系统管理器。此方法适用于 AIR 或 Flash Player。

application.systemManager.addEventListener(FlexEvent.IDLE, onIdle);

您可以使用以下方式获取空闲时间(以不受支持的方式)

SystemManager.mx_internal::idleCounter

See also the idle event in SystemManager. This approach works for AIR or Flash Player.

application.systemManager.addEventListener(FlexEvent.IDLE, onIdle);

You can get the idle time (in an unsupported way) using

SystemManager.mx_internal::idleCounter
安静 2024-08-27 11:43:23

由于这是一个 AIR 应用程序,我可以只监听 NativeApplication 上的 USER_IDLE 事件

//Set seconds for idle
this.nativeApplication.idleThreshold = 5; 
//listen for user idle
this.nativeApplication.addEventListener(Event.USER_IDLE,lock); 

Being that this is an AIR app, I can just listen for the USER_IDLE event on the NativeApplication

//Set seconds for idle
this.nativeApplication.idleThreshold = 5; 
//listen for user idle
this.nativeApplication.addEventListener(Event.USER_IDLE,lock); 
ゝ杯具 2024-08-27 11:43:23

创建一个计时器,每次在应用程序级别捕获用户事件时都会重置该计时器。

如果计时器已结束,那么您就知道用户在设定的时间内处于空闲状态。

// I am capturing only mouseMove and keyDown. That _should_ be enough to handle most user interactions.
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" mouseMove="onUserEvent" keyDown="onUserEvent">

...

private function onUserEvent(event:Event):void
{
    timer.reset();
}

Create a timer that you reset everytime you capture an user event at the application level.

If the timer has ended, then you know the user has been idle for that set amount of time.

// I am capturing only mouseMove and keyDown. That _should_ be enough to handle most user interactions.
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" mouseMove="onUserEvent" keyDown="onUserEvent">

...

private function onUserEvent(event:Event):void
{
    timer.reset();
}
枯寂 2024-08-27 11:43:23

您可以使用以下代码获取超时:

 <?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" 
               minWidth="955" minHeight="600"
               initialize="init(event)">
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.core.mx_internal;
            import mx.events.FlexEvent;

            protected function init(event:FlexEvent):void
            {
                systemManager.addEventListener(FlexEvent.IDLE, handleApplicationIdle);
            }

            private function handleApplicationIdle(event:FlexEvent):void
            {
                if(event.currentTarget.mx_internal::idleCounter == 60){
                    Alert.show("Time out happened");
                }
            }
        ]]>
    </fx:Script>
</s:Application>

You can get the time out by using following code:

 <?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" 
               minWidth="955" minHeight="600"
               initialize="init(event)">
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.core.mx_internal;
            import mx.events.FlexEvent;

            protected function init(event:FlexEvent):void
            {
                systemManager.addEventListener(FlexEvent.IDLE, handleApplicationIdle);
            }

            private function handleApplicationIdle(event:FlexEvent):void
            {
                if(event.currentTarget.mx_internal::idleCounter == 60){
                    Alert.show("Time out happened");
                }
            }
        ]]>
    </fx:Script>
</s:Application>
决绝 2024-08-27 11:43:23

@Michael Brewer-Davis

systemManager.addEventListener(FlexEvent.IDLE, onIdle) 对于鼠标事件效果很好。

键盘事件呢?在 systemManager 监听键盘事件之前,您必须先关注某个元素。

部分解决方案
applicationComplete 事件中,我添加了以下行

   stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);

现在正在监听键盘事件。

缺点:仅在应用程序被点击至少一次后才有效。然后工作正常后

有没有办法让应用程序监听键盘事件而无需单击一次。有些人建议添加stage.focus = this。也不起作用。(仍然需要点击)

@Michael Brewer-Davis

systemManager.addEventListener(FlexEvent.IDLE, onIdle) works fine for mouse events.

What about Keyboard events. You have to have focus on some element before systemManager listens to keyboard events.

Partial Solution:
On applicationComplete event, I added the below line

   stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);

Now keyboard events are getting listened.

Disadvantage: Only works after application is clicked atleast once. Then after works fine

Is there any way to make application listen to keyboard events without hassle of clicking once. Some suggested to add stage.focus = this. Did not work either.(Still click was needed)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文