Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
SudoPlz

How to know whether the down-load was successful or failed.

Recommended Posts

I'm using Loadermax to load a remote binary file (zip).

 

queue.append( new BinaryDataLoader(e.url,{/*name:"test_zip" , */ format:"binary", estimatedBytes:4400000})  );
queue.addEventListener(LoaderEvent.COMPLETE, onDownloadComplete);
queue.addEventListener( LoaderEvent.PROGRESS, onDownloadProgress);
queue.load();

 

I when its complete, i got my .COMPLETE event. but what about when the internet connection goes down? I got no handler for that case..

I noticed i can use HTTP_STATUS, but it fires before complete as well during an error. How can I distinguish those 2 case senarios...

 

Thank you.

Link to comment
Share on other sites

Are you saying that you don't get an ERROR event when the download fails due to a broken connection? 

Link to comment
Share on other sites

Yes you are correct, no LoaderEvent.ERROR event dispatched for the disrupted internet  connection (after the download had started - but not finished).

 

I specifically added each and every LoaderEvent, and then disconnected my device from the Internet to see what events will be dispatched.

The only events that dispatched when i disrupted the connection where, http_status, and complete. No error event.

Link to comment
Share on other sites

LoaderMax passes on any errors it receives from the underlying Adobe classes (like Loader or URLLoader, etc.) so if those don't generate errors, neither will LoaderMax. But is there some reason you can't listen for the HTTP_STATUS event and check the value - that should tell you if it failed. If not, you can just ignore and let the onComplete fire. 

Link to comment
Share on other sites

Ok, I see. I thought the same as well, but I didn't know which value to look for. The data property of the event is null , and the text property is empty.

Link to comment
Share on other sites

You can check the httpStatus of the loader itself (event.target)

Link to comment
Share on other sites

I'll check this out and post back in Monday.. Thanks for helping :)

Link to comment
Share on other sites

I'm having a similar problem - how can I tell from a parent LoaderMax whether or not any of its descendants have failed? Here's a minimal main class to reproduce this problem.

 
package
{
    import com.greensock.loading.LoaderMax;
    import com.greensock.loading.DataLoader;
    import com.greensock.events.LoaderEvent;
    
    import flash.display.Sprite;
    import flash.events.Event;
    
    public class GSTestMain extends Sprite
    {
        protected var loadQueue:LoaderMax;
        
        public function GSTestMain()
        {
            addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler, false, 0, true);
        }
        
        protected function addedToStageHandler(event:Event = null):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
            
            loadQueue = new LoaderMax({ name:"localeQueue", autoDispose:true, auditSize:false });// , onComplete:completeHandler, onError:errorHandler, onFail:errorHandler, onChildFail:errorHandler });
            loadQueue.addEventListener(LoaderEvent.COMPLETE, completeHandler, false, 0, true);
            loadQueue.addEventListener(LoaderEvent.ERROR, errorHandler, false, 0, true);
            loadQueue.addEventListener(LoaderEvent.FAIL, errorHandler, false, 0, true);
            loadQueue.addEventListener(LoaderEvent.CHILD_FAIL, errorHandler, false, 0, true);
            
            var configQueue:LoaderMax = new LoaderMax({ autoDispose:true, auditSize:false });
            configQueue.append(new DataLoader("en_US.xml"));
            
            loadQueue.append(configQueue);
            loadQueue.load();
        }
        
        protected function completeHandler(event:LoaderEvent):void
        {
            trace("completeHandler");
        }
        
        protected function errorHandler(event:LoaderEvent):void
        {
            trace("errorHandler");
        }
    }
}
 
The file "en_US.xml" does not exist. I get the output:
 
completeHandler
----
Error on DataLoader 'loader1' (en_US.xml): Error #2032: Stream Error. URL: file:///D|/Users/Dave/Documents/GitHub/flash%5Fgames/bin/swf/en_US.xml
----
 
The parent LoaderMax fires a complete event, and does not fire an error, fail, or child fail event, even though one of its descendants failed, even though an error is traced out by some gs class. Is this the expected behavior? This seems problematic for 2 reasons.
 
1. The parent LoaderMax should report when any of its descendants fail. I think this may be an actual bug.
 
2. The parent LoaderMax should not report complete when any of its descendants fail. I think I recall talking about this with you before, and correct me if I'm wrong, but you were of the opinion that the parent LoaderMax should report complete when all its descendants finish their business, whether they have loaded successfully or not.
 
I know that an error event doesn't necessarily mean the loader has failed (there could be an alternateURL), so there's a fail event to unambiguously indicate failure. If indeed a complete event doesn't necessarily mean the loader has loaded successfully (a child may have failed), shouldn't there be a "success" event or the like to unambiguously indicate success?
 
I updated my gs classes today before trying this.
 
P.S. The order of the output traces also seems problematic.  If I did get an error event in addition to the complete event, it would do me a lot more good before the complete event, so I'd know what kind of "complete" this is and what the specific error was, rather than having to wait for the error event.
Link to comment
Share on other sites

Yes, there was an issue in LoaderMax that caused it to remove event listeners prematurely in a particular scenario like the one you ran into, but I believe it's fixed in the latest version which you can get at http://www.greensock.com/?download=GSAP-AS3 Would you mind testing that and letting us know if it works well for you? 

 

As for LoaderMax dispatching a complete event even if one or more of the children fails, I think that is definitely the correct default behavior because most people don't want the whole queue to just stop and not complete if only one (or some subset) loader fails. You can, however, get the behavior that you were requesting by setting the LoaderMax's skipFailed property to false. That will cause it to NOT complete if any of its children fails. 

 

Thanks for the detailed description of things and code sample. 

Link to comment
Share on other sites

Thank you for addressing this so quickly.  The problem is fixed: now I get an error event and a child failed event before the complete event.  If I set skipFailed to false on loadQueue, I still get the complete event.  I have to set skipFailed on both loadQueue and configQueue to prevent the complete event and get a fail event instead.  Just making sure this is the intended behavior - skipFailed refers only to immediate children, not any descendant.

Link to comment
Share on other sites

Good point - I think it would be more intuitive if skipFailed applied to everything inside the LoaderMax instance. Would you mind trying the attached [updated] version of LoaderMax to see if it works as expected for you? 

LoaderMax.as.zip

Link to comment
Share on other sites

Yes, this seems to work right for my example.  Now I only have to set skipFailed on loadQueue to prevent the complete event and get a fail event.

Link to comment
Share on other sites

Nope, skipPaused would be instance-specific. 

Link to comment
Share on other sites

Would the same logic not apply? Would it be more intuitive if skipPaused applied to everything inside the LoaderMax instance? Also, it might be more intuitive if the behavior of skipPaused was consistent with the behavior of skipFailed.

Link to comment
Share on other sites

I can understand why you'd think it should be handled identically, but skipPaused is much more complex to implement that way and would bloat the file size and slow things down due to extra conditional logic such that I don't think the benefits outweigh the costs to everyone. You're literally the only person who has ever requested something like that in all the years that LoaderMax has been out in the wild (unless my memory is failing me). If there was a lot of demand for that, I'd think it'd be worth consideration but it's extremely rare that folks use skipPaused:false and even more rare to worry about that in deeply nested LoaderMax instances. If you need that functionality, you can either loop through the children and make sure that the LoaderMax instances all have skipPaused:false or just getChildren() and set the omitLoaderMax parameter to true and loop through those and append() them to a new LoaderMax whose skipPaused is false. It should be relatively easy. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×