首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >闪存处于非活动状态一段时间后的navigateToURL

闪存处于非活动状态一段时间后的navigateToURL
EN

Stack Overflow用户
提问于 2013-06-20 00:20:51
回答 1查看 74关注 0票数 0

如果鼠标在三分钟内没有移动,我希望重启我的应用程序。我使用"navigateToURL“返回到第一个场景,但是如何使用ActionScript3实现这样的定时事件呢?

EN

回答 1

Stack Overflow用户

发布于 2013-06-21 14:27:01

这很简单--你需要使用两个事件监听器:

  1. MouseEvent.MOUSE_MOVE event listener
  2. TimerEvent.TIMER事件侦听器

您还需要一个Timer对象

下面是代码

代码语言:javascript
复制
    //private timer var in your class
    private var myLittleTimer:Timer;

    //This is your main function, where you adding all the event listeners
    //IMPORTANT NOTE:
    //We can only track mouse movement over the flash stage in a DisplayObject that
    //has the link to the main stage
    //For example, your main SPRITE
    yourMainFunction():void{
        //Timer initialization
        this.myLittleTimer = new Timer(3000, 1);
        this.myLittleTimer.addEventListener(TimerEvent.TIMER, lazinessDetector);
        this.myLittleTimer.start();

        this.addEventListener(Event.ADDED_TO_STAGE, init);
    }
    private function init(e:Event):void{
        this.removeEventListener(Event.ADDED_TO_STAGE, init);
        //THIS IS THE ENTRANCE POINT
        //do not use stage object before the sprite has been added to the stage
        //as it will cause a null object exception

        //We add a MOUSE_MOVE event listener to the stage to track the moment when
        //the mouse has moved
        stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
    }
    private function onMouseMove(e:MouseEvent):void{
        this.myLittleTimer.reset();
        this.myLittleTimer.start();
        //This function will reset the "countdown" timer and start it over again.
    }
    private function lazinessDetector(e:TimerEvent):void {
        //YOUR URL REDIRECT CODE GOES HERE
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17196346

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档