簡體   English   中英

在Flash處於非活動狀態一段時間后

[英]navigateToURL after a period of inactivity in Flash

如果三分鍾內沒有移動鼠標,我想重啟我的應用程序。 我使用“ navigateToURL”返回第一個場景,但是如何使用動作腳本3實現這樣的定時事件呢?

這非常簡單-您需要使用兩個事件監聽器:

  1. MouseEvent.MOUSE_MOVE事件偵聽器
  2. TimerEvent.TIMER事件偵聽器

您還需要一個Timer對象

所以這是代碼

    //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
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM