URLLoader cancel load on any browser event
I have a flash element in a page that load a chart based on some complex queries that can take up to a minute to load. I call the query with this code :
var chartData:URLLoader = new URLLoader();
chartData.addEventListener(Event.COMPLETE, onLoaded);
chartData.addEventListener("httpStatus", onHttpStatus);
chartData.load(new URLRequest(chartURL));
I listen for the complete event or any server error event.
My problem is when a user want to go on another page while the flash is loading the URL : the browser is waiting for the url to be fully loaded before accepting the req开发者_运维知识库uest of the user. As I say this chart can take up to a minute to load and it's kind of annoying for my users to wait if they want to change page.
Here is my question : Is there is an event to listen any event from the browser (click on another link, click on the "back" button of the browser...) ? If I'm wrong in my way to do this don't hesitate to tell me, I'm not really used to program in flash.
Thank you.
I think I understand what you're describing. Some things you might want to try out:
File Upload HTTP Server
If the files are very large, you might want to load them on another HTTP server, like Nginx. Check out the Nginx Upload Module (I'm sure Apache has the same thing). That basically allows you to upload files without making the user feel the impact at all.
The only problem with this is that it's pretty complex, and you won't know when the file is done uploading. But they do have examples of how to show Upload Progress Bars with Nginx using Javascript, so you could do something like that, and on completion (in javascript), send a message to flash that invokes something like your Event.COMPLETE
handler.
Browser Events
There are browser events to intercept with Javascript to prevent your user from leaving the page until the download has completed (not recommended as it may annoy the user):
- onexit
- onclose
- onblur (when they click somewhere else)
Check out this example: Javascript onclose: Warn the User.
Hope that helps, Lance
精彩评论