为什么 browseForOpen 可能无法显示文件对话框,但在调用时声称它已打开?

Why might browseForOpen fail to display File Dialog yet claim it is open if recalled?

我正在尝试使用 file.browseForOpen 打开一个文件对话框。大多数时候它都可以工作,但在极少数情况下(例如在会议中)文件浏览器根本不会出现并且不会阻止(作为模态应该)。

如果我此时按下调用代码的按钮,则会收到一条错误消息,指出 "there can only be one"。

没有 sub-windows,即使在最小化主 window 之后我也找不到文件对话框,但错误坚持认为它是打开的。我写了一些代码,在调用上面的代码时禁用按钮,然后在任何事件上启用它,但是当发生此错误时,按钮将被永久禁用。

还有另外 10,000 行代码,其中一些即使在文件浏览器打开时也会保持 运行。 None 其中似乎与文件浏览器有关,所以我将以下代码移动到一个新项目中进行测试,但无法复制该错误。

var filter:FileFilter = new FileFilter("Image/Video", "*.jpg;*.png;*.mp4;");
var imagesFilter:FileFilter = new FileFilter("jpg/png", "*.jpg;*.png");
var docFilter:FileFilter = new FileFilter("mp4", "*.mp4;");
var filters:Array = [filter, imagesFilter, docFilter];

var fileBrowser:File = File.userDirectory;
fileBrowser.addEventListener(FileListEvent.SELECT_MULTIPLE, onFileSelected);
fileBrowser.addEventListener(Event.CANCEL, clean);
fileBrowser.addEventListener(IOErrorEvent.IO_ERROR, clean);
fileBrowser.browseForOpen("Select Slides", filters);

有谁知道可以让我免于 'needle in a haystack' 详尽搜索的任何方法吗?有没有其他人遇到过同样的问题?在搜索 "File dialog opens but isn't visible" 或该搜索的 30 多个变体(包括 "File dialog doesn't open".

时,我找不到任何解决方案

最后,如果我检测到用户正在与主 window 交互而应该被阻止,是否有办法强制关闭文件对话框?就像绷带修复一样,如果问题没有得到解决(破坏模态流,我知道,但模态流在那个时候已经被破坏了)。

更新:

删除 class 并将其替换为效率较低的 urlMonitor 后,问题似乎已经消失。 如果有人能找出问题所在,那么我会将您的答案标记为完整。 我删除的 class 似乎完全无关,但我将显示代码:

package reuse.Network
{
    import flash.desktop.NativeApplication;
    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.events.IOErrorEvent;
    import flash.events.StatusEvent;
    import flash.events.TimerEvent;
    import flash.net.URLLoader;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLRequest;
    import flash.utils.Timer;

    import air.net.URLMonitor;

    [Event(name="networkStatusChanged", type="reuse.Network.CheckInternetEvent")]
    public class NetStatusMonitor extends EventDispatcher
    {
        private var url:String;
        private var urlMonitor:URLMonitor;

        public function NetStatusMonitor(url:String = 'http://www.adobe.com')
        {
            super();
            this.url = url;
        }

        protected function onNetwork_ChangeHandler(event:Event):void
        {
            checkWebsite(url, dispatchStatus);
        }

        /**
         * Checks a specific website for connectivity.
         * @param uri URI of the website to check for a response from
         * @param result Function which accepts a bool as a response.
         * @param idleTimeout How many milliseconds to wait before timing out
         */
        public function checkWebsite(uri:String, result:Function, idleTimeout:Number = NaN):void
        {
            var timeout:Timer;
            var request:URLRequest = new URLRequest(uri);

            if(!isNaN(idleTimeout))
            {
                request.idleTimeout = idleTimeout;

                timeout = new Timer(request.idleTimeout + 1000, 1);
                timeout.addEventListener(TimerEvent.TIMER_COMPLETE, failed);
                timeout.start();
            }

            var loader:URLLoader = new URLLoader();
            loader.dataFormat = URLLoaderDataFormat.TEXT;
            loader.addEventListener(Event.COMPLETE, complete);
            loader.addEventListener(IOErrorEvent.IO_ERROR, failed);
            loader.load(request);

            function complete():void
            {
                result(true);
                cleanup();
            }

            function failed(e:*):void
            {
                result(false);
                cleanup();
            }

            function cleanup():void
            {
                if(timeout)
                {
                    timeout.stop();
                    timeout.removeEventListener(TimerEvent.TIMER_COMPLETE, failed);
                    timeout = null;
                }

                loader.close();
                loader.removeEventListener(Event.COMPLETE, complete);
                loader.removeEventListener(IOErrorEvent.IO_ERROR, failed);
                loader = null;
            }
        }

        public function start():void
        {
            checkWebsite(url, dispatchStatus, 5000);

            if(!NativeApplication.nativeApplication.hasEventListener(Event.NETWORK_CHANGE))
                NativeApplication.nativeApplication.addEventListener(Event.NETWORK_CHANGE, onNetwork_ChangeHandler);

            if(urlMonitor == null)
            {
                var request:URLRequest = new URLRequest(url);
                urlMonitor = new URLMonitor(request);
                urlMonitor.pollInterval = 30;
            }

            if(!urlMonitor.hasEventListener(StatusEvent.STATUS))
                urlMonitor.addEventListener(StatusEvent.STATUS, onNetStatus_ChangeHandler);

            if(!urlMonitor.running)
                urlMonitor.start();
        }

        public function stop():void
        {
            if(urlMonitor)
            {
                if(urlMonitor.running)
                    urlMonitor.stop();

                if(urlMonitor.hasEventListener(StatusEvent.STATUS))
                    urlMonitor.removeEventListener(StatusEvent.STATUS, onNetStatus_ChangeHandler);

                urlMonitor = null;
            }
        }

        private function onNetStatus_ChangeHandler(event:StatusEvent):void
        {
            dispatchStatus(urlMonitor.available);
        }

        private function dispatchStatus(status:Boolean):void
        {
            dispatchEvent(new CheckInternetEvent(CheckInternetEvent.NETWORK_STATUS_CHANGED, status));
        }
    }
}

任何熟悉 Raja Jaganathan 的人都可能从 Adobe Air - Check for internet connection

中认出这个 class

我将此作为错误发布到 Adob​​e,并添加了以下注释:

Alex Rekish

11:06:11 PM GMT+00:00 Apr 12, 2016

I have seen this problem and found workaround. You need remove listeners, force cancel and null pervious file object that you you for browseForOpen method.

previousBrowseFile.removeEventListener(Event.SELECT, fileSelected); previousBrowseFile.removeEventListener(Event.CANCEL, fileCancelled); previousBrowseFile.cancel(); previousBrowseFile= null;