I think this is a mistake in the URLLoader class.
If you read the error message (at least the one I received, you did not insert yorrs!), You will see the following:
Error: error # 2029: this URLStream object does not have an open stream on flash.net::URLStream/readBytes () on flash.net::URLLoader/onComplete ()
This gives you some idea of ββwhat is going on. The URLLoader class internally uses the URLStream object, which provides low-level access to loaded data.
The error message indicates that the onComplete handler is being called on the URLLoader. The file is large, but it is probably cached, so it loads pretty quickly. Now, if you add a listener for both progress and full events, you will see the order in which events are fired:
docs confirm this:
Note that the httpStatus event (if any) is dispatched before (and, in addition, to) any complete event or error.
Now you can see that the problem is that you are calling close () from the state handler. This closes the stream. But apparently (and this is an error), the onComplete handler in the URLLoader class does not check if the stream is open. (From Actionscript there is no way to verify this, so you have to wrap the code in try / catch). You cannot read data from a closed stream, which is why it is blowing.
I see two ways to fix this:
1) Cancel the execution of the function that calls the close () method (unload method), so the call to close () is called after calling the onComplete URLLoader internal method.
That is, do the following:
setTimeout(unload,1);
instead of this:
unload();
2) Use URLStream instead of URLLoader. The first option seems like a bit of a hacky workaround for me, so I would go with that last one in your situation. Using a URLStream means more work on your side, as a rule, but in this case you are actually not interested in reading any data, so it does not really matter. In addition, you will need to change two lines in the current code:
This:
private var _loader:URLStream;
And this one:
_loader = new URLStream();
And you are all set.