• [AIR] AS3.0设置屏保功能


    package com.controls
    {
        import flash.desktop.NativeApplication;
        import flash.events.Event;
        import flash.events.EventDispatcher;
        import flash.events.IEventDispatcher;
        
        /**
         * @author:Frost.Yen
         * @E-mail:871979853@qq.com
         * @create:    2016-6-21 下午3:24:57
         *
         */
        public class ScreenSaver extends EventDispatcher
        {
            static public const START_SAVER:String = "start_saver";
            static public const QUIT_SAVER:String = "quit_saver";
            public function ScreenSaver(target:IEventDispatcher=null)
            {
                super(target);
            }
            public function set scrrenSaverTime(value:Number):void 
            {
                NativeApplication.nativeApplication.idleThreshold = value;
                NativeApplication.nativeApplication.addEventListener(Event.USER_IDLE, handleUserIdle);
                NativeApplication.nativeApplication.addEventListener(Event.USER_PRESENT, handleUserPresent);
            }
            /**
             * 当用户处于空闲状态的时间长度达到 idleThreshold 属性指定的时间时调度。
             */
            private function handleUserIdle(e:Event):void 
            {
                //开始屏保
                this.dispatchEvent(new Event(START_SAVER));
                trace("鼠标离开了多少秒", NativeApplication.nativeApplication.timeSinceLastUserInput);
            }
            
            /**
             * 当操作系统在空闲一段时间后检测到鼠标或键盘活动时调度。
             */
            private function handleUserPresent(e:Event):void 
            {
                //退出屏保
                this.dispatchEvent(new Event(QUIT_SAVER));
                
            }
        }
    }

    用法:

    package  
    {
        import com.controls.ScreenSaver;
        import flash.display.Sprite;
        import flash.events.Event;
        
        /**
         * ...
         * @author FrostYen
         */
        public class Main extends Sprite 
        {
            private var _saver:ScreenSaver;
            public function Main() 
            {
                _saver = new ScreenSaver();
                _saver.scrrenSaverTime = 0.5;
                _saver.addEventListener(ScreenSaver.START_SAVER, onStartSaver);
                _saver.addEventListener(ScreenSaver.QUIT_SAVER, onQuitSaver);
            }
            
            private function onStartSaver(e:Event):void 
            {
                trace("start_saver");
            }
            
            private function onQuitSaver(e:Event):void 
            {
                trace("quit_saver");
            }
            
            
        }
    
    }
  • 相关阅读:
    Codeforces 1131 C. Birthday-暴力 (Codeforces Round #541 (Div. 2))
    Codeforces 1131 B. Draw!-暴力 (Codeforces Round #541 (Div. 2))
    DP之背包经典三例
    博弈规律综概
    腾讯面试题:杯子质量(最优查找)
    洛谷P1308——单词统计
    AtCoder Regular Contest 069 D
    Codeforces 782C. Andryusha and Colored Balloons 搜索
    Codeforces 799D. String Game 二分
    Codeforces 767B. The Queue 模拟题
  • 原文地址:https://www.cnblogs.com/frost-yen/p/5603912.html
Copyright © 2020-2023  润新知