I would really like some help to do this the 'right' way. So all comments very welcome.
Problem: LoaderMax is set up and the queue is given the command to load.
eg:
queue = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});
queue.append( new XMLLoader(Object(parent).currentCity +".xml", {name:"currentCity"}) );
queue.load();
loadProgressBar.scaleX=0; loadProgressBar.visible=true; loadProgressBarBG.alpha=1; //returns removed for forum
function progressHandler(event:LoaderEvent):void {
loadProgressBar.scaleX=event.target.progress;
}
function completeHandler(event:LoaderEvent):void {
//actions when load complete
}
but connection is good = no error and data name is correct = no error data is available = no error but
due to busy traffic or other problem the data loads only v. v. slowly or not at all. Effectively killing the site since no error is generated.
In the absence of a 'TimeOut' function in the loader itself the solution I thought up was to set up a timer to check after, in this case, 10 seconds how far the load has progressed. If it is less than say 5% then to try and reload. If the load completes well in advance of the timer then the completeHandler function must, of course, kill the timer:
....
queue.load();
loadProgressBar.scaleX=0; loadProgressBar.visible=true; loadProgressBarBG.alpha=1; //returns removed for forum
var timeOut:Timer = new Timer(10000,1);
function timeOutListener (e:TimerEvent):void {
if (loadProgressBar.scaleX <= 0.05) {
// HERE I NEED TO THE CORRECT CODE TO STOP / DISPOSE OF AND RESTART A SECOND LOAD ATTEMPT
}
timeOut.removeEventListener(TimerEvent.TIMER, timeOutListener);
timeOut.stop();
}
timeOut.addEventListener(TimerEvent.TIMER, timeOutListener);
timeOut.start();
function progressHandler(event:LoaderEvent):void {
loadProgressBar.scaleX=event.target.progress;
}
function completeHandler(event:LoaderEvent):void {
timeOut.removeEventListener(TimerEvent.TIMER, timeOutListener);
timeOut.stop();
// actions when load complete
}
Ideally I would actually further modify the timer so that It would retry once or twice and the final time would perhaps simply stop the load and return to another area of the site displaying the appropriate warning (just mentioned for info)
the code I have used for the restart =
if (loadProgressBar.scaleX <= 0.05) {
queue.empty(true, true);
queue.append( new XMLLoader(Object(parent).currentCity +".xml", {name:"currentCat"}) );
queue.load();
loadProgressBar.scaleX=0;
}
Would such a sequence of actions stop, empty and restart a load?
Feedback and improvements gratefully accepted!
Mark