0

我正在编写一个通用的 OAuth 组件(是的,它将是开源的),我想检测用户是否单击了 htmlView 上的关闭小部件(或者更准确地说,它的浏览器窗口)

我尝试在 htmlView 和 html.stage.nativeWindow 上都放置 CLOSE 侦听器,但无济于事。

提前致谢

4

1 回答 1

0

此代码可能会有所帮助

package com.bigspaceship.core.air
{
    // flash
    import flash.display.NativeWindow;
    import flash.desktop.NativeApplication;    

    import flash.events.Event;
    import flash.events.EventDispatcher;

    public class NativeWindowManager extends EventDispatcher
    {
        private var _window            :NativeWindow;
        private var _isMainWindow    :Boolean;
        public var isQuitBlocked    :Boolean;

        public static const PROMPT    :String        = "windowQuitPrompt";

        public function NativeWindowManager($window:NativeWindow,$isMainWindow:Boolean = false):void
        {
            _window = $window;
            _isMainWindow = $isMainWindow;
            _window.addEventListener(Event.CLOSING,_windowOnClose,false,0,true);
        };

        public function get window():NativeWindow { return _window; };

        private function _mainWindowOnClose($evt:Event):void
        {
            $evt.preventDefault();

            if(isQuitBlocked) dispatchEvent(new Event(PROMPT));
            else close();
        };

        public function close():void
        {
            _window.removeEventListener(Event.CLOSING,_windowOnClose);

            if(_isMainWindow) NativeApplication.nativeApplication.exit();
            else _window.close();

            _window = null;
        };
    };
};
于 2013-01-06T01:32:46.030 回答