Question

I am using navigateToURL for file downloading from server. Is there anyway possible to know when navigateToURL has finished, more like when browser download dialog has opened?

Sometimes it takes 5 seconds to complete, user might get confused and start clicking download button like psychopath, which can result in multiple download dialogs opened.

I want to add some "please wait" text or something before it finishes (I already have one, I just need to know when to stop).
Maybe it can be done using javascript and get info from ExternalInterface?

Was it helpful?

Solution

Is there anyway possible to know when navigateToURL has finished, more like when browser download dialog has opened?

No, there is not. Once you pass a request onto the browser; the Flash Player no longer has any control or access to it.

You mention using ExternalInterface as part of a possible solution, but how would your HTML/JavaScript page know that a download had been finished?

OTHER TIPS

This is kind of crazy, but I can't think of any other way: you could put the request object into a dictionary which is set to weak reference the keys, and then check on intervals whether the key was removed.

However, I'm not sure what will happen first, either the SWF itself will be disposed or the dictionary will be cleaned. It's also possible that given the one-time-ness of the function the reference to the request object isn't deleted because it is assumed to be deleted together with the whole SWF.

One more thing that I know is that uncaught error events will catch events from navigateToURL - not really helpful, but at least may give you the indication if it didn't work.

One more simple thing I can think of - just disable the button for a short time, like 1-2 seconds. If it worked, no one will see the delay, and if it didn't, they won't be able to press it too often.

private var _requestStore:Dictionary = new Dictionary(true);
private var _timer:Timer = new Timer(10);
. . .
_timer.addEventListener(TimerEvent.TIMER, timerHandler);
. . .
public function openURL(url:String):void
{
    var request:URLRequest = new URLRequest(url);
    _requestStore[request] = true;
    _timer.start();
    navigateToURL(request);
}

private function timerHandler(event:TimerEvent):void
{
    var found:Boolean;
    for (var o:Object in _requestStore)
    {
         found = true;
         break;
    }
    if (!found) // the request got disposed
}

navigateToURL does not fire a complete event. Try using this event from Adobe's help documentation:

public function URLRequestExample() {
        loader = new URLLoader();
        configureListeners(loader);

        var request:URLRequest = new URLRequest("XMLFile.xml");
        try {
            loader.load(request);
        } catch (error:Error) {
            trace("Unable to load requested document.");
        }
    }

    private function configureListeners(dispatcher:IEventDispatcher):void {
        dispatcher.addEventListener(Event.COMPLETE, completeHandler);
        dispatcher.addEventListener(Event.OPEN, openHandler);
        dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
        dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
        dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
        dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    }

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html#includeExamplesSummary

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top